I have to manage "VBOX_USER_HOME" and "vboxmanage setproperty machinefolder" for multiple users on the same computer.
For this, I've created four scripts.
-- num 1 - change VBOX_USER_HOME -----
option explicit
on error resume next
dim WshShell, env, Shell, user_name
' User which had opened session:
Set WshShell = CreateObject("WScript.Shell")
Set Shell = WshShell.Environment("Process")
user_name = Shell("username")
' VBOX_USER_HOME creation:
Set WshShell = CreateObject("WScript.Shell")
set env=WshShell.Environment("User")
env("VBOX_USER_HOME") = "D:\" & user_name & "\vbox"
Set WshShl = Nothing
WScript.Quit()
-------------------------------------------------
-- num 2 - delete VBOX_USER_HOME -----
option explicit
on error resume next
dim WshShell, env
' Delete the variable:
Set WshShell = CreateObject("WScript.Shell")
set env=WshShell.Environment("User")
env.remove "VBOX_USER_HOME"
If Err.Number <> 0 Then
if CStr(Hex(Err.Number)) = 80070002 then
' Prehaps VBOX_USER_HOME don't exists.
err.clear
else
wscript.echo CStr(Hex(Err.Number)) & " - " & Err.Description
end if
end if
Set WshShell = Nothing
WScript.Quit()
------------------------------------------------
-- num 1 - change machinefolder ----------
option explicit
on error resume next
dim WshShell, env, Shell, user_name, final_dir
' User which had opened session:
Set WshShell = CreateObject("WScript.Shell")
Set Shell = WshShell.Environment("Process")
user_name = Shell("username")
final_dir = "D:\" & user_name & "\vbox"
call Wshshell.Run ("cmd /k c:\""program files""\oracle\virtualbox\vboxmanage setproperty machinefolder " & final_dir, 1, True)
If Err.Number <> 0 Then
wscript.echo CStr(Hex(Err.Number)) & " - " & Err.Description
else
end if
Set Wshshell = Nothing
Set Shell = Nothing
WScript.Quit()
-------------------------------------------------
-- num 2 - restore machinefolder ----------
option explicit
on error resume next
dim objargs, WshShell, env, Shell, user_name, final_dir
' User which had opened session:
Set WshShell = CreateObject("WScript.Shell")
Set Shell = WshShell.Environment("Process")
user_name = Shell("username")
final_dir = "C:\Documents"" ""and"" ""Settings\" & user_name & "\VirtualBox"" ""VMs"
call Wshshell.Run ("cmd /k c:\""program files""\oracle\virtualbox\vboxmanage setproperty machinefolder " & final_dir, 1, True)
If Err.Number <> 0 Then
wscript.echo CStr(Hex(Err.Number)) & " - " & Err.Description
else
end if
Set WshShell = Nothing
Set Shell = Nothing
WScript.Quit()
-------------------------------------------------
All scripts seems to work fine:
- scripts 1 and 2: I see (or not if deleted), my user environment variable VBOX_USER_HOME with the right value (I see it in Microsoft > System > Advanced > Environment variables > User variables),
- scripts 3 and 4: "c:\program files\oracle\virtualbox\vboxmanage list systemproperties" give me the good value for "Default machine folder".
My problem: sometimes, but not at each time, after script 1 (VBOX_USER_HOME creation), when I launch graphical virtual box manager, vbox use the environment variable, or not. I see VBOX_USER_HOME in Microsoft > System > Advanced > Environment variables > User variables, with the new right value, but VBox don't use it. But not at each time...
What's happened ?
Thanks for all.
Best regards.
(All this on XP SP3).
VBOX_USER_HOME and vbs
-
boucherle
- Posts: 18
- Joined: 7. Nov 2010, 00:00
- Primary OS: MS Windows XP
- VBox Version: OSE other
- Guest OSses: Win seven
Re: VBOX_USER_HOME and vbs
It's working.
After script 1, you have to wait a few seconds (0 to 20 seconds), before launch the graphical console of virtual box.
After script 1, you have to wait a few seconds (0 to 20 seconds), before launch the graphical console of virtual box.