''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ' This script first starts services for VMWARE, then starts VMWARE Workstation. ' Once VMWARE stops, services are stopped and terminated again. ' Prerequisites for this script: ' Modify: Computer Management -> Services -> VMware Virtual Mount Manager Extended ->Startup Type:Manual ' Modify: Computer Management -> Services -> VMware Nat Service ->Startup Type:Manual ' Modify: Computer Management -> Services -> VMware DHCP Service ->Startup Type:Manual ' Modify: Computer Management -> Services -> VMware Authorization Service ->Startup Type:Manual ' Remove HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\VMware hqtray ' Remove HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\vmware-tray ' ' written 080821 by w_m0zart / Marc Nijdam. http://www.nijdam.de/marc.html ' modified by Angaran Stefano http://blog.upyou.it ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set FSO = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") dim pth dim pgm1 dim pgm2 dim pgm3 dim cmnd dim qq set shell = Wscript.CreateObject("Wscript.shell") qq = Chr(34) ' define quote as constant, because shell.run does not accept a program without this function ' Program to start with command line options pth = "C:\Program Files\VMware\VMware Workstation\" pgm1 = "vmware.exe" pgm2 = "hqtray.exe" pgm3 = "vmware-tray.exe" cmnd = "" rem Now starting services startservice ("VMAuthdService") startservice ("VMnetDHCP") startservice ("VMware NAT Service") 'startservice ("vmount2") ' rimuovere il primo apice della riga se si sta usando VMWare 6.0.x shell.run qq & pth & pgm2 & qq,0,false shell.run qq & pth & pgm3 & qq,0,false shell.run qq & pth & pgm1 & qq & cmnd,1,true ' now starting vmware.exe rem Now stopping services stopservice ("VMAuthdService") stopservice ("VMware NAT Service") 'stopservice ("vmount2") ' rimuovere il primo apice della riga se si sta usando VMWare 6.0.x stopservice ("VMnetDHCP") termService ("hqtray.exe") ' service which cannot be stopped with the function stopservice (...) termService ("vmware-tray.exe") ' service which cannot be stopped with the function stopservice (...) rem Removing registry key If objRegistry.EnumValues (HKLM, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run\vmware-tray", arrValueNames, arrValueTypes) = 0 Then shell.RegDelete( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\vmware-tray") ' Remove this particular key again from the registry, since vmware wrote this back End If sub startservice (StrService) ' Start a service with its service name in the Windows Services (via Computer Management) c = 0 Do Until c = 1 Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name = '" & StrService & "'") For Each objService in colServiceList Select Case objService.State Case "Stopped" objService.StartService() c = 1 Case "Running" c = 0 Case "Start Pending" c = 0 End Select Next WScript.Sleep (1000) Loop End Sub sub stopservice (StrService) ' Stop a service with its service name in the Windows Services (via Computer Management) c = 0 Do Until c = 1 Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name = '" & StrService & "'") For Each objService in colServiceList Select Case objService.State Case "Stopped" c = 1 Case "Running" objService.StopService() c = 0 Case "Start Pending" c = 0 End Select Next WScript.Sleep (1000) Loop End Sub sub termService (StrService) ' Stop a service with name StrService corresponding in the Windows Task Manager Dim colProcessList, objProcess Set colProcessList = GetObject("Winmgmts:").ExecQuery("Select * from Win32_Process Where Name ='" & StrService & "'") For Each objProcess in colProcessList objProcess.Terminate( ) Next End sub