01 February 2006
Switching Virtual Machines Full screen and back quickly
So I can't admit to having written this, but I thought it was worth sharing. It's also a good example of how to use WMI to find out if a process is running, start new processes up and kill of running processes from VBScript.
Save the below as a .VBS file somewhere on your local machine. Then create a shortcut to it on your desktop and setup a keyboard quick-key access to the shortcut through the properties of the shortcut.
Assuming the virtual machine is running, you can do (assuming Z is the keystroke) type Ctrl+Alt+Z to switch between your desktop and a virtual machine. Of course, change the virtual machine name and DNS name accordingly (highlighted in yellow).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
set sh = CreateObject("wscript.shell")
strCmdLine = "C:\Program Files\Microsoft Virtual Server\VMRC Client\vmrc.exe"
strArgs = "-fullscreen " & chr(34) & _
"vmrc://localhost:5900/Contoso Client" & chr(34)
'//Determine if VMRC is running?
Set colProcesses = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = " & "'VMRC.exe'")
'//If the VMRC Process is running - Launch it, otherwise terminate it.
If colProcesses.Count = 0 Then
sh.Run chr(34) & strCmdLine & chr(34) & " " & strArgs,,False
Else
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'VMRC.EXE'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
End If
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.