# How to start a virtual machine via a scheduled task?

I want to "start" a virtual machine (it may be powered down or hibernating) via a scheduled task in Windows 7. I cannot figure the correct way to do this.

I tried scheduling the cmd task, which works if I run it manually.

cmd "x:\test1.vmcx"


None of the applications in the Virtual PC area of system32 seem to be working with arguments.

c:\windows\system32\vpc.exe "x:\test1.vmcx"
c:\windows\system32\vmwindow.exe "test1"
c:\windows\system32\vmwindow.exe "x:\test1.vmcx"


And I tried the VMSal command described here, without an application argument (I used my machine's 2nd param, not one listed in the command).

c:\Windows\System32\VMSal.exe "test1" "||2073a9cc"

-

Make a batch file with this in it:

"C:\path\to\VMWindow.exe" -file "C:\full\path\to\file.vmcx"

Replace values accordingly, as I do not know where your Virtual PC installation is situated. Keep the quotes just in case, as any path with spaces in it will break your batch script (ie: Virtual PC).

Save this and run the .bat file from task scheduler.

-
There is no virtualpc.exe in Windows Virtual PC (for Windows 7). There is a vpc.exe (the process that shows in Task Manager when VPC is running). The Start Menu shortcut "Windows Virtual PC" goes to vmwindow.exe. And XP Mode style application shortcuts are vmsal.exe. –  Anthony Mastrean Dec 14 '09 at 17:12
You'll want vmwindow –  John T Dec 14 '09 at 17:34
I can execute the batch file from the command line, but it is not working from Scheduled Tasks even with highest privileges. –  Anthony Mastrean Dec 14 '09 at 21:24

I managed to create a PowerShell script that would execute the *.vmcx file in the Explorer registered application.

& 'x:\test1.vmcx'


I then registered the PowerShell executable as my task "action" and the path to this script as an "argument".

<path-to-ps>\powershell.exe x:\start-test1.ps1

-
Using just the script as the task "program" opens in Notepad... even though it has a PowerShell icon. I don't want to mess with this behavior, so I use the PowerShell program and argument. –  Anthony Mastrean Dec 14 '09 at 22:28
The command window closes after execution using the PS script! –  Anthony Mastrean Dec 15 '09 at 16:30

I managed to get a batch file to work. The batch file leans on Explorer.

x:\test1.vmcx


I just make it the "program" in the Scheduled Task action.

x:\start-test1.bat

-
I can't get the command window to disappear after execution... any thoughts? –  Anthony Mastrean Dec 15 '09 at 16:20