Page 1 of 2

Shutdown VM On Logoff

Posted: 14. Mar 2010, 07:40
by saberman
Host: Windows 7 Ultimate x64
Guests: Windows 7 Ultimate x64

I am using VirtualBox on my development machine. I currently start and stop the VMs I need manually. I would like a clean way to automatically shutdown any VM that is running when I logoff.

I have tried a logoff script with VBoxManage but it runs too late in the logoff process. Windows sends VirtualBox a close command before running the logoff script and VirtualBox then stops with the do you want to save, etc. dialogbox.

Re: Shutdown VM On Logoff

Posted: 14. Mar 2010, 09:36
by jorgensen
An alternative is to use Close->Save the Machine State which is very fast and do what you request.

Re: Shutdown VM On Logoff

Posted: 14. Mar 2010, 15:07
by saberman
jorgensen wrote:An alternative is to use Close->Save the Machine State which is very fast and do what you request.
That is what I am currently doing. I need a way of doing it automatically when my userid is logged off.

Re: Shutdown VM On Logoff

Posted: 14. Mar 2010, 15:22
by vbox4me2
Build a delay in the logoff script, or ping test until that fails, then logoff.

Re: Shutdown VM On Logoff

Posted: 14. Mar 2010, 16:36
by saberman
vbox4me2 wrote:Build a delay in the logoff script, or ping test until that fails, then logoff.
The logoff script is run by the system as part of the logoff process. As I stated in my first post the problem is that the system runs the logoff script after it signals all running processes to end. IOW, the timing line is:

1. Logoff process begins -- triggered by either a manual logoff request or by the Windows OS as part of a shutdown process.
2. Windows signals all tasks running under the user to close.
3. VitualBox gets the close signal and hangs waiting for the user to respond to its request for the type of close to do.
4. The OS then runs the logoff script.

Please note that the logoff script I am talking about is one that is define through a group policy option that a script that I run to logoff the macine. The former is run automatically (but too late in the process) -- the later has to be run manually and is not what I need.

Re: Shutdown VM On Logoff

Posted: 14. Mar 2010, 23:13
by vbox4me2
Yes I know, I use the same system at logoff or shutdown, but the same policy also has values about 'run at the same time', you have to set these accordingly and it will work as you want.

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 16:02
by saberman
vbox4me2 wrote:Yes I know, I use the same system at logoff or shutdown, but the same policy also has values about 'run at the same time', you have to set these accordingly and it will work as you want.
I think you are refering to:
Run logoff scripts synchronously
Enable this option to run logoff scripts before the user logs off.

However, as noted at: http://technet.microsoft.com/en-us/libr ... S.10).aspx
This is appears to only be available in the group policy editor on a server. I am running on a standalone workstation that is not connected to a domain. The policy does not appear when running the local group policy editor gpedit.msc.

Is there a registry hack to implement this policy on a standalone workstation?

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 17:10
by vbox4me2
There are more policies on disk then mmc initially shows, I can't see at the moment which one I used but its there by default and works.

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 19:16
by saberman
vbox4me2 wrote:There are more policies on disk then mmc initially shows, I can't see at the moment which one I used but its there by default and works.
I opened a blank MMC console and added the Group Policy Object which open the Select Group Policy Object dialog box. The only GPO choices were Local Computer and individual users. Neither had the Run Logoff Scripts Synchronously policy.

If you remember how you got to it please post the information here.

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 20:53
by vbox4me2

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 22:01
by saberman
Both of the above discuss running a script at shutdown and not how to enable Logoff Scripts Synchronously on a standalone workstation. I have the script in the correct folder and it runs at logoff but too late. The question is how to enable Logoff Scripts Synchronously on a standalone workstation?

Re: Shutdown VM On Logoff

Posted: 15. Mar 2010, 23:55
by vbox4me2
Then it has to be some policy setting as it works at shutdown and logoff just as the articles describes. You might have set values that should not be set.

Re: Shutdown VM On Logoff

Posted: 16. Mar 2010, 01:07
by saberman
vbox4me2 wrote:Then it has to be some policy setting as it works at shutdown and logoff just as the articles describes. You might have set values that should not be set.
The only policy I set was to define a script to be run a logoff. The normal operation for a standalone workstation that has a logoff script set is for the script to be run toward the end of the logoff process after running tasks have been told to close. This is what is happening on my workstation -- per the description for running a logoff script. Unfortunately, that is too late in the logoff process to use VBoxManage to shutdown VMs running under VirtualBox -- VirtualBox has already been told to close and hangs waiting for a response from the user.

You said your logoff script runs early enough to shutdown a VM running under VirtualBox. As near as I can tell that requires enabling the "Run logoff scripts synchronously"policy. The question is did you enable that policy without being part of a domain -- that is on a standalone workstation? If you did how did you do it?

Re: Shutdown VM On Logoff

Posted: 16. Mar 2010, 11:39
by vbox4me2
Yes but you can reverse that policy setting, there are 2 settings which influence each other and a reboot is required when changing them, I'd have to look later on again to see what exactly is broadcasted as a policy. The Host is not a domain member. I might have used a logoff shortcut to a script or changed the classid pointing logoff to elsewhere.

Re: Shutdown VM On Logoff

Posted: 16. Mar 2010, 16:01
by saberman
vbox4me2 wrote:I might have used a logoff shortcut to a script or changed the classid pointing logoff to elsewhere.
Would this cover the case where the logoff was initiated by the system not the user?