Sheduling Virtual Machine start/stop in Win8 pro

Answered Sheduling Virtual Machine start/stop in Win8 pro

  • Sunday, January 27, 2013 2:20 PM
     
     

    Windows8 pro x64 - VirtualBox 4.2.6

    Hi. I'm trying to get a VirtualBox VM to automatically start when i boot the computer/login and stop (saving the state) when i logoff or shutdown. I have the VB commands needed to do this, but so far i failed to get them to work correctly when i need them to run.

    First, i tried to use Task Sheduler but there is no logoff event so i can start the VM when i log in, but not stop it automatically. Then i looked at Local group policies using gpedit.msc. I created 2 very simple (actually just 1 line) powershell scripts (i tested them and they do work), but when i put them in the login/logout scripts i can't get them to work. The logout script especially won't work. Here is what happens when i log out or shutdown (as i will be logged out before the shutdown, i guess logout scripts will run)

    • I select logout from the start screen
    • I get an error that tells me VirtualBox won't close and ask me to either force quit or cancel
    • I cancel so i can close VB, but VB will crash if i try to save at that time, probbaly because some required processes are already off
    • After doing this i logout again
    • Now i see the PowerShell prompt appear quickly and try to run my script (i enabled visual display to help me understand what's happening)

    Seing this, i guess Win8 first tries to close VirtualBox and it's processes, then only run the logoff scripts (so my script does nothing). I need the logoff script to run before win attempts to terminate processes as the script will take care of closing my VM correctly. Unfortunately, enabling PowerShell scripts to run first doesn't change this. This option seems to be only for VBscript vs PowerShell scripts order.

    Also, when the login script runs, the VM tries to start but fails to do and i get a COM error from VBox (and won't be able to start VBox manually either). This might be because the VM wasn't closed correctly, but might also be caused by the script running before some required processes are launched.

    Well, 2 questions then :

    1. Is there a way to run some command line at logoff apart from using group policy (such as using a journal event as a trigger in Task Sheduler if there is an event that gets recorded at every logoff). Obviously i need this command to run before Windows tries to terminate any running application.
    2. Is there a way to make a group policy script that runs at logoff before Windows tries to terminate any running application and at login after all processes are started.

All Replies

  • Sunday, January 27, 2013 6:43 PM
     
     

    The VM should be saved on a shutdown or logoff.  Why do you think you need to shut it down with a script?

    Starting a VM with the Task Scheduler as a 'logon' task should work.


    ¯\_(ツ)_/¯


  • Monday, January 28, 2013 11:05 AM
     
     

    I need to shut it down with a script to give it a save command so it will save the current state and quit rather than block the shutdown process. If you read my post, you'll see that when i try to shut-down or logoff with the VM running, Windows will report that an application can't be closed, than i need to click cancel or "force quit". That's why i'm trying to use a script.

    Yes starting with Task Sheduler does work, as i said it's the shutdown that's giving me issues. Group Policy script was just for consistancy.

  • Monday, January 28, 2013 1:48 PM
     
     

    I need to shut it down with a script to give it a save command so it will save the current state and quit rather than block the shutdown process. If you read my post, you'll see that when i try to shut-down or logoff with the VM running, Windows will report that an application can't be closed, than i need to click cancel or "force quit". That's why i'm trying to use a script.

    Yes starting with Task Sheduler does work, as i said it's the shutdown that's giving me issues. Group Policy script was just for consistancy.

    Looks like your out of luck then.

    Why not just let thee VM auto-save on shutdown.  Why do you think you have to do it with a script?


    ¯\_(ツ)_/¯

  • Monday, January 28, 2013 1:54 PM
     
     
  • Monday, January 28, 2013 2:12 PM
     
     

    Here is a better description of how to configure a VM.

    http://www.petri.co.il/setting-virtual-machine-boot-options-windows-sever-2008-hyper-v.htm

    This thread should be moved to the OS forum as it is not a scripting issue.


    ¯\_(ツ)_/¯

  • Monday, January 28, 2013 2:49 PM
     
     
    What is strange here is that the default action on shutdown is to save the VM.  If you have changed this then you must know about the VM configuration.  Check the settigns to be sure that you have them set up to auto-start and auto-save.  They are at the bottom of the settings menu/screen.

    ¯\_(ツ)_/¯

  • Monday, January 28, 2013 10:20 PM
     
     

    I hadn't built a VM on Windows 8 before this so I thought I should do it to see how well it matches earlier builds.  I decided to build an old XP system and see how things went.

    The build was successful.  The default is still what it has been which is to automatically start any VMs running when the system was last chutdown.  Shutting down the system saves the current VM state automatically.

    Ther is no need to use a scipt or to schedule a shutdown or save with MS Hyper-V on Windows 8.  It performs exactly as would be expected.  We can also override teh default behavior to always start a VM or to never save a VM as we need.  All of this is done, of course, with the VM 'Settings'.  As far as I can tell nearly all of this can be configured via PowerShell.

    YOu should not need to alter any thing to get the best behavior.  Just wizard your VM and go.


    ¯\_(ツ)_/¯

  • Tuesday, January 29, 2013 10:02 AM
     
     

    First line of my opening post : Windows8 pro x64 - VirtualBox 4.2.6 so please don't point me to hyper-v documentation. I decided to use Virtual Box after i found hyper-v wouldn't give me the level of integration i wanted

    So let me ask this again : is there a way to schedule a task to run automatically at each logout, but before windows send the termination signal to running apps? Is it that hard to answer a precise question?


    EDIT : Move this to another place if this one is wrong. I posted here because my searches showed multiple sheduling questions asked in this forum.
    • Edited by r0k Tuesday, January 29, 2013 10:07 AM
    •  
  • Tuesday, January 29, 2013 10:18 AM
     
     Answered

    Sorry but Vboxie has pretty much the same settings. If you have issues post with the vendor here: https://forums.virtualbox.org/

    I don't use virtualbox so I will leave it to you to look up the settings fro autosave and autostart.

    No there is no way to run a task at logout.

    Remember that a VM exists even after the logout.  It is autosaved on a shutdown of the service or of the PC.  On shutdown the VM is saved if it as not been set to revert.  Hyper-V and most otherVMs can respond to a UPS shutdown on the host.

    Think of it this way...  What would be the value of a PC or server that loses all of its work on a shutdown?

    ¯\_(ツ)_/¯