Vboxmanage SCCM Script

Discussions related to using VirtualBox on Windows hosts.
Post Reply
AngGB
Posts: 4
Joined: 14. Jul 2021, 13:42

Vboxmanage SCCM Script

Post by AngGB »

Hello,

I've been trying to deploy a batch script with VboxManage commands using SCCM/MECM, it runs the script but no changes are made. Here are the commands used:

Code: Select all

"c:\program files\oracle\virtualbox\VBoxManage.exe" registervm "C:\VMs\VM.vbox"
"c:\program files\oracle\virtualbox\VBoxManage.exe" storageattach "VM" --storagectl "SATA" --device 0 --port 0 --medium none
"c:\program files\oracle\virtualbox\VBoxManage.exe" modifyhd "c:\VMs\Programming.vdi" -type immutable -autoreset on
"c:\program files\oracle\virtualbox\VBoxManage.exe" storageattach "Programming" --storagectl "SATA" --device 0 --port 0 --type hdd --medium "c:\VMs\Programming.vdi"
"c:\program files\oracle\virtualbox\VBoxManage.exe" setextradata "VM" GUI/RestrictedCloseActions SaveState,PowerOff
"c:\program files\oracle\virtualbox\VBoxManage.exe" setextradata global GUI/Customizations noMenuBar,noStatusBar,noSelector
The batch script works when I run it manually but when I set it as a GPO startup script or install via SCCM/MECM, the VM isn't registered and none of the changes are made.

Any advise would be appreciated.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Vboxmanage SCCM Script

Post by scottgus1 »

Virtualbox requires a user environment and account to run in. If GPO or SCCM/MECM runs the script under other than the account you are logging into, the changes go into the GPO/SCCM/MECM account's user folder, not yours, so the changes don't appear.

Alternatively, the Virtualbox process may not be ready yet during GPO/SCCM/MECM runtimes. Try adding some text file logging to your batch file, to see what happens. Maybe:

'echo {what the above line commanded} %errorlevel% >> C:\Users\Public\Batchfile.log'

after each line of the batch file?
AngGB
Posts: 4
Joined: 14. Jul 2021, 13:42

Re: Vboxmanage SCCM Script

Post by AngGB »

scottgus1 wrote:Virtualbox requires a user environment and account to run in. If GPO or SCCM/MECM runs the script under other than the account you are logging into, the changes go into the GPO/SCCM/MECM account's user folder, not yours, so the changes don't appear.
I was afraid that would be the case.
scottgus1 wrote:Alternatively, the Virtualbox process may not be ready yet during GPO/SCCM/MECM runtimes. Try adding some text file logging to your batch file, to see what happens. Maybe:

'echo {what the above line commanded} %errorlevel% >> C:\Users\Public\Batchfile.log'

after each line of the batch file?
Here is what I get:

Code: Select all

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" registervm "C:\VMs\vm.vbox" 
VBoxManage.exe: error: Trying to open a VM config 'C:\VMs\vm.vbox' which has the same UUID as an existing virtual machine
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "OpenMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 86 of file VBoxManageMisc.cpp

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" storageattach "vm" --storagectl "SATA" --device 0 --port 0 --medium none 

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" modifyhd "c:\VMs\vm.vdi" -type immutable -autoreset on 
VBoxManage.exe: error: Medium 'C:\VMs\vm.vdi' is not differencing
VBoxManage.exe: error: Details: code VBOX_E_NOT_SUPPORTED (0x80bb0009), component MediumWrap, interface IMedium, callee IUnknown
VBoxManage.exe: error: Context: "COMSETTER(AutoReset)(AutoReset)" at line 780 of file VBoxManageDisk.cpp

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" storageattach "vm" --storagectl "SATA" --device 0 --port 0 --type hdd --medium "c:\VMs\vm.vdi" 

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" setextradata "vm" GUI/RestrictedCloseActions SaveState,PowerOff 

C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" setextradata global GUI/Customizations noMenuBar,noStatusBar,noSelector
When I launch the vbox console it doesnt show the vm in the list and it doesn't have the lockdown customisations above.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Vboxmanage SCCM Script

Post by scottgus1 »

Your posted output shows two errors:
AngGB wrote:"c:\program files\oracle\virtualbox\VBoxManage.exe" registervm "C:\VMs\vm.vbox"
VBoxManage.exe: error: Trying to open a VM config 'C:\VMs\vm.vbox' which has the same UUID as an existing virtual machine
Your VM has already been registered, so it does not need to be registered again.
AngGB wrote:C:\WINDOWS\system32>"c:\program files\oracle\virtualbox\VBoxManage.exe" modifyhd "c:\VMs\vm.vdi" -type immutable -autoreset on
VBoxManage.exe: error: Medium 'C:\VMs\vm.vdi' is not differencing
I'm not sure if this means that the disk must be set to differencing first then immutable, or if it can't be set to immutable because it's previously being used in a way that is not compatible with being immutable.

Lest we end up chasing an "XY problem", could you please tell us what is the problem you're trying to solve, or the final result you hope to achieve? Maybe this script is not the best way.
AngGB
Posts: 4
Joined: 14. Jul 2021, 13:42

Re: Vboxmanage SCCM Script

Post by AngGB »

Thank you.

I did see the error stating it was already registered but i can see the VM in the list so who knows where it is registered. Additionally, it looked like it applied the restrictions to vbox but this doesnt seem to be the case when i launch it.

As to what I'm trying to do, I want to copy the VM to the machines in the computer lab and register the VM. The VM (or its drive anyway) is set to immutable so no changes area saved to the VM when the VM is powered and shutdown. The additional settings are so the user/students are restricted in a way they cannot create or make changes to the current VM. In previous years we've been able to do this on the image for the computer but we are moving over to SCCM/MECM. We can get vbox to install and copy over the VM but cannot get it to do the last bit properly, that is register the VM and restrict vbox.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Vboxmanage SCCM Script

Post by scottgus1 »

AngGB wrote:i can see the VM in the list so who knows where it is registered.
I'll gather that you meant "can't" :D
I would look through the Users folders on the available accounts on the PCs to see where a ".Virtualbox" folder (note the period in the name) exists. Among these .Virtualbox folders will be a Virtualbox.xml file with the VM registered. It should be the same account the script is running under.

Apparently the old method used the same account the student would use, whereas the new method is using a different account. You'd have to figure out what account the script is running under through GPO or SCCM/MECM.

if a VM with the proper settings is in place already, it might be reset by copying the VM folder. Once it's registered it will find the refreshed folder files and keep right on going (though I am not certain where the "immutable" state of the hard drive is kept, whether in the drive file itself or in the Virtualbox.xml or the VM's .vbox file).

Alternatively, you should consider adding an "unregister" command to kill off the existing VM before adding the newly-copied VM.

FWIW a reasonably savvy Virtualbox user can completely undo the lockdowns you are trying to impose. The settings are all in the VM's .vbox file, and maybe the Virtualbox.xml file, which the user account running the VM must have complete write access to, so either by opening the main Virtualbox window or by editing the .vbox file after the Virtualbox VboxSVC service has shut down, all the lockdowns can be removed.
AngGB
Posts: 4
Joined: 14. Jul 2021, 13:42

Re: Vboxmanage SCCM Script

Post by AngGB »

Sorry i thought i had responded to this but turns out it didnt post because i was auto-logged off.

Anyway yes i meant can't.

From what you've stated i've figured it out and its all sorted now. I was missing the addition of VBOX_USER_HOME, after that and a few tweaks to logging, i've been able to create a script/application in MECM/SCCM that will deploy a VM.

Angus.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Vboxmanage SCCM Script

Post by scottgus1 »

AngGB wrote:VBOX_USER_HOME
Ha! I'd forgotten about this!

Glad you're up and running!
Post Reply