Virtual machine is Windows XP professional 32.
Host machine is Widows 10 64 in an active directory environment.
I have the virtual machine saved in a public documents folder, and I want the virtual machine to start when a user logs into it. Is there a way to automatically add a virtual machine on login for each respective user? I have a bat file that launches the virtual machine on login, but it only works if the virtual machine has already been added to VirtualBox.
Here's my code to start the vm:
PAUSE
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm 39bab4e3-de43-4247-8c20-35f63fa35058
Automatically add virtual machine on log in.
-
- Site Moderator
- Posts: 20945
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: Automatically add virtual machine on log in.
This is expected. Virtualbox runs in the user space and requires the guest to be registered in Virtualbox first before it can run. Different users can see different lists of guests.KyleAH wrote:it only works if the virtual machine has already been added to VirtualBox.
You can use the ' Vboxmanage registervm "driveletter:\path\to\.vboxfile" ' command to register the guest in your batch file before you start the guest.
In my test, if the guest is already registered, the "registervm" command errors out and allows the next start command to run.
Re: Automatically add virtual machine on log in.
so I did a work around if anyone is interested.
1. virtual machine is located in public folder. Name MCA74 Clone
2. bat file runs a vbs file at login
3. vbs file checks if a shortcut to the VM on the desktop exists. If yes, then starts vm. If no, then adds virtual machine, adds shortcut to desktop and then starts vm. (note: the pauses are necessary in some places, but not in others...
.bat file at C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
wscript "C:\Users\Public\AddVM.vbs"
.vbs file located in C:\Users\Public
1. virtual machine is located in public folder. Name MCA74 Clone
2. bat file runs a vbs file at login
3. vbs file checks if a shortcut to the VM on the desktop exists. If yes, then starts vm. If no, then adds virtual machine, adds shortcut to desktop and then starts vm. (note: the pauses are necessary in some places, but not in others...
.bat file at C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
wscript "C:\Users\Public\AddVM.vbs"
.vbs file located in C:\Users\Public
Code: Select all
Set x = CreateObject("WScript.Shell")
Set objFileSys = CreateObject("scripting.FileSystemObject")
yLink = "MCA74 Clone.lnk"
zDesktop = x.SpecialFolders("Desktop")
If objFileSys.FileExists(zDesktop & "\" & yLink) Then
x.run """C:\Program Files\Oracle\VirtualBox\VirtualBox.exe"""
wscript.sleep 2000
x.sendkeys "{ENTER}"
ELSE
x.run """C:\Program Files\Oracle\VirtualBox\VirtualBox.exe"""
wscript.sleep 2000
x.sendkeys "^a"
wscript.sleep 2000
x.sendkeys "C:\Users\Public\New group\MCA74 Clone"
wscript.sleep 500
x.sendkeys "{ENTER}"
wscript.sleep 300
x.sendkeys "MCA74 Clone.vbox"
wscript.sleep 500
x.sendkeys "{ENTER}"
wscript.sleep 1000
x.sendkeys "m"
wscript.sleep 150
x.sendkeys ("+{F10}")
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 300
x.sendkeys "{DOWN}"
wscript.sleep 150
x.sendkeys "{DOWN}"
wscript.sleep 300
x.sendkeys "{ENTER}"
wscript.sleep 1000
x.sendkeys "m"
x.sendkeys "{ENTER}"
End If
Last edited by socratis on 24. May 2017, 22:46, edited 1 time in total.
Reason: Enclosed the information in [code] tag for better readability
Reason: Enclosed the information in [code] tag for better readability
-
- Site Moderator
- Posts: 27329
- Joined: 22. Oct 2010, 11:03
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Win(*>98), Linux*, OSX>10.5
- Location: Greece
Re: Automatically add virtual machine on log in.
I haven't written scripts for years (Windows at least), but Scott's solution seems to be ... simpler and (thus) more robust. Because it doesn't depend on the existence or not of a shortcut in the users' desktop, it's independent of that.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.