When using the unnatended class, did I find a bug or am I doing it wrong? If you set GuestAdditionsInstall to true and add the postInstallScriptTemplatePath attribute, then postInstallScriptTemplatePath will overwrite the guestAdditionsInstall script file that was created in the machine's unnatended folder. Then the add-ons will not be installed and will simply be executed after the installation script. Or in short, the postscript attribute removes the installation scripts of the guest additions and adds its own to the file scripts.
- Code: Select all Expand viewCollapse view
IUnattended un = vbox.createUnattendedInstaller();
createmachine(mgr, vbox, machinename);
IMachine machinefind = vbox.findMachine(machinename);
ISession session = mgr.getSessionObject();
machinefind.lockMachine(session, LockType.Write);
un.setIsoPath("F:\\ru_windows_8.1_professional_vl_with_update_x64_dvd_4050520.iso");
un.detectIsoOS()
IMachine machwrite = session.getMachine();
un.setMachine(machwrite);
un.setUser(pcname);
un.setFullUserName(machinename);
un.setProductKey("");
un.setPostInstallScriptTemplatePath("K:\\VM Lib\\PostScriptps.ps1");
un.setInstallGuestAdditions(true);
un.setTimeZone("Russian Standard Time");
un.setLocale("ru_RU");
un.prepare();
un.constructMedia();
un.reconfigureVM();
un.done();
session.unlockMachine();