Creating a package from scratch

Top  Previous  Next

The following example creates a brand new package, from pre-defined files and registry keys. To create a new package from an installer, see Online Packaging APIs.

It then adds three files into it, and one empty dir (which will obtain a "Full access" isolation exception later).

It sets "mine.exe" as the AutoLaunch file.

It also adds a registry key and value into the package ("Hello world"), and later sets that key's isolation to "Full access".

Finally, it saves the file and closes.


// Create package from scratch

if (PackageCreate(L"MyVirtualPackage", FullMyPath(L"AppVirtDll.dll"), 

 FullMyPath(L"Loader.exe"), &hPkg) == APIRET_SUCCESS)


   // Add files to package

   VirtFsAdd(hPkg, L"c:\\now\\win7.png", L"%windows%\\win7.png", FALSE);                   // Add file

   VirtFsAdd(hPkg, L"c:\\now\\install.ini", L"%Program Files%\\MyDir\\install.ini", TRUE); // Add file

   VirtFsAdd(hPkg, L"c:\\now\\mine.exe", L"%Program Files%\\MyDir\\mine.exe", FALSE);      // Add file

   VirtFsAddEmptyDir(hPkg, L"%Program Files%\\MyDir\\TempDir", FALSE);                     // Add empty folder


   // Set some basic properties

   PackageSetProperty(hPkg, L"AutoLaunch", L"%Program Files%\\MyDir\\mine.exe");           // Set AutoLaunch (important!)

   PackageSetIconFile(hPkg, L"c:\\now\\mine.exe");                                         // Set icon


   // Add registry entries to package

   CString WorkKey;

   VirtRegGetWorkKey(hPkg, WorkKey.GetBuffer(MAX_PATH), MAX_PATH);                         // Obtain read/write reg key


   RegWriteString(HKEY_CURRENT_USER, WorkKey + L"\\Machine\\Software\\MySoft", L"SomeValue", L"Hello world");



   // Manipulate isolation (default = isolated)

   SandboxSetRegistryFlags(hPkg, L"Machine\\Software\\MySoft", FALSE, SANDBOXFLAGS_PASSTHROUGH); // Full access

   SandboxSetFileFlags(hPkg, L"%Program Files%\\MyDir\\TempDir", FALSE, SANDBOXFLAGS_PASSTHROUGH); // Full access


   // Save & close package

   PackageSave(hPkg, PackageName);




This sample does not check for errors.
FullMyPath and RegWriteString are private, self-explanatory functions; replace them with your own.


The resulting package looks like this: