Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: cannot shutdown after using shutdown script

05 Jan 2013   #11
Duzzy

Windows 7 Ultimate x64
 
 

That's cool, your post is valid nonetheless.


My System SpecsSystem Spec
.
06 Jan 2013   #12
JAYBEEV

Windows 7 Professional 32-bit
 
 

Thanks guys, I appreciate all the efforts.

@marsmimar: I didn't find the registry key that you described. The shutdown command also does not work when run from the command prompt.

@kari: I didn't notice that error.. but still, that was not the problem. In fact, I believe the script was supposed to display a message box, but it doesn't.. when I click the shutdown button, it just closes everything, and then logoff, then displays the "shutting down" message but doesn't turn the computer off. I tried waiting up to 5 minutes... still nothing.

@DavidW7ncus: I really don't know what to look for in the policy editor.. and as far as I see, everything seems to be "not configured"..

@Duzzy: I tried to run the shutdown command from the prompt, but the effect is the same.

Just like marsmimar's idea, I think adding the script changed something in the registry, but I don't know where to start looking.. It seems too simple, but I want to do the repair install when everything else fails.. any more ideas? Thanks.
My System SpecsSystem Spec
07 Jan 2013   #13
Duzzy

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by JAYBEEV View Post
@Duzzy: I tried to run the shutdown command from the prompt, but the effect is the same.
Not sure if you mean you tried "shutdown -a" or "shutdown -s" from the command promt but just to be clear like Kari said
Quote   Quote: Originally Posted by Kari View Post
If no delayed shutdown process is active, the shutdown -a does nothing:
Quote   Quote: Originally Posted by Kari View Post
Delayed shutdown after X seconds:
Code:
shutdown -s -t X
Kari
Another words the only way "shutdown -a" does anything is when "shutdown -t xx" has been ran to start a delayed shutdown or "shutdown -s" as this also provides a 1 minute or so delay. When you click Shutdown on the start menu or press the power button on the PC it immediately starts to shutdown with no delay.
Quote   Quote: Originally Posted by JAYBEEV View Post
@kari: I didn't notice that error.. but still, that was not the problem. In fact, I believe the script was supposed to display a message box, but it doesn't.. when I click the shutdown button, it just closes everything, and then logoff, then displays the "shutting down" message but doesn't turn the computer off. I tried waiting up to 5 minutes... still nothing.
I have preformed a couple quick test and you need to change another setting in gpedit to get it to display the message but "shutdown -a" does not work even if it's the first command in the script because of the my words above and the fact that the script is ran too late into the shutdown process.
Quote   Quote: Originally Posted by JAYBEEV View Post
@DavidW7ncus: I really don't know what to look for in the policy editor.. and as far as I see, everything seems to be "not configured"..
Have you double checked that your script has been removed from the shutdown scripts and maybe the logoff scripts if you played around trying to get it to work?
Quote   Quote: Originally Posted by JAYBEEV View Post
Just like marsmimar's idea, I think adding the script changed something in the registry, but I don't know where to start looking.. It seems too simple, but I want to do the repair install when everything else fails.. any more ideas? Thanks.
I tested the same script on my testing installation to see if I could reproduce your problem but I did not have any problems shutting down after the script was removed. While the script was set up to run it would hang on shutdown untill you clicked yes or no on the message and because you can not see the message it will probably hang indefinitely. With verbose shutdown enabled it hung on "Please wait for the Group Policy Client", so again I would double check that your script has been removed.
My System SpecsSystem Spec
.

07 Jan 2013   #14
UsernameIssues

W7 Pro SP1 64bit
 
 

Please post the contents of these files:
"%SystemRoot%\system32\GroupPolicy\gpt.ini
"%SystemRoot%\system32\GroupPolicy\Machine\Scripts\scripts.ini

The "no shutdown" behavior is repeatable using any line that requires user interaction. I tested inside a virtual machine using only this line:
Code:
menuSel=MsgBox("test", vbYesNo)
The action occurs and the user cannot interact with it - thus the hang.

I wonder why MS just did not process a logoff and then a shutdown? I guess that takes too long.

Anyway, when I set a shutdown script via gpedit, it changed these areas of the registry:
cannot shutdown after using shutdown script-shutdown-reg.png
and again here for a 64 bit OS
cannot shutdown after using shutdown script-shutdown-reg2.png
You might want to manually (and carefully) snoop around those areas to make sure that nothing is pointing to something.


My System SpecsSystem Spec
07 Jan 2013   #15
UsernameIssues

W7 Pro SP1 64bit
 
 

@Duzzy, It took me so long to compose and post what I did - I missed seeing your post.

Quote   Quote: Originally Posted by Duzzy View Post
~~~
Another words the only way "shutdown -a" does anything is when "shutdown -t xx" has been ran to start a delayed shutdown. When you click Shutdown on the start menu or press the power button on the PC it immediately starts to shutdown with no delay.
~~~
I'm not picking at your declaration, just refining it.
Test this in a batch file:
Code:
shutdown -s
pause
shutdown -a
pause
As long as there is some delay, (which shutdown -s has some delay), then you can abort.

This does not abort
Code:
shutdown -s -t 0
shutdown -a
pause
Quote   Quote: Originally Posted by Duzzy View Post
~~~
I have preformed a couple quick test and you need to change another setting in gpedit to get it to display the message.....
~~~
I don't know too much about GPO settings - what needs to be changed to allow user interaction with a shutdown script?
My System SpecsSystem Spec
07 Jan 2013   #16
Duzzy

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by UsernameIssues View Post
The "no shutdown" behavior is repeatable using any line that requires user interaction. I tested inside a virtual machine using only this line:
Code:
menuSel=MsgBox("test", vbYesNo)
The action occurs and the user cannot interact with it - thus the hang.
I would like to just note for anybody that comes across this thread that you can interact with a script by changing a setting in gpedit under,

Computer Configuration > Administrative Templates > System > Scripts

Here you'll find "Run shutdown scripts visible" and "Run Startup scripts visible". Change both or only the one you need to interact with. Also under,

User Configuration > Administrative Templates > System > Scripts

You'll find "Run logon scripts visible" and "Run logoff scripts visible".

For those with Windows versions without access to gpedit I believe there are ways to run shutdown scripts but I don't know about other scripts or interacting with them. Interaction maybe possible by adding the registry values which are all DWORD's with their data value set to 0.
warning   Warning
1. Any changes to the registry could result in a non-working computer.
2. If the registry change does not enable interaction the system will hang during the running of the script and a forced reboot will be required.
3. If the script is a startup or logon then it will be ran again after a forced reboot so I would not recommend trying either of these
EDIT
I did find a setting in gpedit that suggest the maximum hang time while processing a script would be 10mins unless changed. Read more for "Maximum wait time for Group Policy scripts" under,

Computer Configuration > Administrative Templates > System > Scripts

I claim no responsibility if you cannot boot.
END EDIT


HideStartupScripts
HideShutdownScripts

Above two DWORD's under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" and

HideLogoffScripts
HideLogonScripts

DWORD's under "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System"

These registry keys are for 64bit Windows. 32bit bit I would think are the same but I take no responsibility for errors.
My System SpecsSystem Spec
07 Jan 2013   #17
Duzzy

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by UsernameIssues View Post
I don't know too much about GPO settings - what needs to be changed to allow user interaction with a shutdown script?
I was actually in the middle of writing a post explaining that as you posted check post #16 above.

Quote   Quote: Originally Posted by UsernameIssues View Post
Quote   Quote: Originally Posted by Duzzy View Post
~~~
Another words the only way "shutdown -a" does anything is when "shutdown -t xx" has been ran to start a delayed shutdown. When you click Shutdown on the start menu or press the power button on the PC it immediately starts to shutdown with no delay.
~~~
I'm not picking at your declaration, just refining it.
Test this in a batch file:
Code:
shutdown -s
pause
shutdown -a
pause
As long as there is some delay, (which shutdown -s has some delay), then you can abort.
Opps I knew that, you are absolutely correct "shutdown -s" does provide a 1 min or so delay and I have modified my post to state that, thank you.
My System SpecsSystem Spec
08 Jan 2013   #18
JAYBEEV

Windows 7 Professional 32-bit
 
 

Quote   Quote: Originally Posted by Duzzy View Post
...

HideShutdownScripts

Above two DWORD's under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" and

...
The good news is, this one worked! I added this to my registry, and now I can see the message and shutdown. I also tried removing the script, and it also shuts down properly.

Thank you very much.

The bad news is, the Yes/No option in the message doesn't work.. Both "Yes" and "No" proceeds to a shutdown. I even tried adding an else statement to the script, "shutdown -a", but it didn't work.

well, at least now I can shutdown properly.. hahaha..
My System SpecsSystem Spec
08 Jan 2013   #19
Duzzy

Windows 7 Ultimate x64
 
 

Good to hear you can shutdown normally.

Quote   Quote: Originally Posted by JAYBEEV View Post
Quote   Quote: Originally Posted by Duzzy View Post
...

HideShutdownScripts

Above two DWORD's under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" and

...
The good news is, this one worked! I added this to my registry, and now I can see the message and shutdown. I also tried removing the script, and it also shuts down properly.
You should have been able to enable this by gpedit, although it probably doesn't really matter adding it straight to the registry will not tell you that it is enabled when viewing in gpedit.

Quote   Quote: Originally Posted by JAYBEEV View Post
The bad news is, the Yes/No option in the message doesn't work.. Both "Yes" and "No" proceeds to a shutdown. I even tried adding an else statement to the script, "shutdown -a", but it didn't work.
I tried to explain earlier that it won't work because
Quote   Quote: Originally Posted by Duzzy View Post
...."shutdown -a" does not work even if it's the first command in the script because of the my words above and the fact that the script is ran too late into the shutdown process.
Also note
Quote   Quote: Originally Posted by Duzzy View Post
Another words the only way "shutdown -a" does anything is when "shutdown -t xx" has been ran to start a delayed shutdown or "shutdown -s" as this also provides a 1 minute or so delay. When you click Shutdown on the start menu or press the power button on the PC it immediately starts to shutdown with no delay.
If you would like to use a shortcut to shutdown the PC you can use a script that ask the questions and if ok then shutdown using "Shutdown -s" or "shutdown -s -t xx" or if something has been forgotten do nothing or display a message that shutdown has been aborted. For example,
Code:
Set WshShell=WScript.CreateObject("WScript.Shell")
On Error Resume Next
menuSel=MsgBox("Have you completed your timesheet ?" & vbCrLf & "Have you sent in the Invoice?" & vbCrLf & "Have you forgotten anything at all?" & vbCrLf & "Think hard!", vbYesNo)
If menuSel=vbNo Then
    WshShell.Run "Shutdown -s"
Else
    MsgBox "Shutdown has been aborted", vbOKOnly
End If
You may need to re-word your questions as to me it reads yes, yes, no or no, no, yes, so I wasn't sure if you wanted to shutdown on a yes or no.

The way I've written the script is if you click No it shutdowns with a 1min or so delay giving you time to manually abort with "shutdown -a" or if you click Yes it displays "Shutdown has been aborted" in a message box. To shutdown without delay use "shutdown -s -t 0" or to add more delay use "shutdown -s -t xx" replacing xx with the number of seconds you wish to delay for. I recommend at least the 1min delay in case you click the wrong button you can abort it.

To prevent using Shutdown from the Start Menu you can remove it via gpedit by enabling "Remove and prevent access to the Shut Down, Restart, Sleep, and Hibernate commands" found under,

User Configuration > Administrative Templates > Start Menu and Taskbar

This will only remove the commands from the Start Menu and the page that displays when you press "Ctrl + Alt + Del", this will not prevent other ways including software set to shutdown. Although this all works for shutting down I don't know any way to prevent logging off or a way to log off via a script if that matters
EDIT but you can remove logoff from the start menu or all ways to log off.

To remove logoff from start menu use "Remove logoff on the Start Menu" in the same path as above or to remove all ways use "Remove logoff on the Start Menu" and "Remove Logoff" under

User Configuration > Administrative Templates > System > Ctrl + Alt + Del Options

END EDIT

To prevent shutting down by the PC's power button set the action in the Advanced Power Settings in the Power Options for the power plans you use.

One last thing I did find a setting in gpedit that suggest the maximum hang time while processing a script would be 10mins unless changed. Read more for "Maximum wait time for Group Policy scripts" under,

Computer Configuration > Administrative Templates > System > Scripts
My System SpecsSystem Spec
08 Jan 2013   #20
Duzzy

Windows 7 Ultimate x64
 
 

I made some edits above if you have already read it.
My System SpecsSystem Spec
Reply

 cannot shutdown after using shutdown script




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Wanting a Script or Program to shutdown PowerDVD13 after ripped movie
Is there anyone that can create some sort of script or small program that could possibly stay alive in the background, watch for when powerdvd13 starts in cinema mode and when the movie stops, have the program shutdown PDVD and bring WMC to the front? - BACKGROUND - -Front End- I am using...
Media Center
Single Monitor shutdown script
Hi I have recently started using multiple monitors but due to my second monitor having a VGA connection it defaults to the primary display when starting up and it shows the bios and windows log on and only once windows has started will it revert back to my DVI primary display. My question is:...
Customization
Logoff script not running at shutdown
I have a script that launches Ccleaner and needs to run at shutdown. Shutdown scripts do not run within the user space as I understand, so I figured I'd use a logoff script which will run while the user is still logged in. The logoff script works when logging off as expected, but does not run...
General Discussion
VBS script that shutdown other pc in network.
Hi, I got an VBS script to shutdown pc in network remote.. Option Explicit Dim objShell, strComputer, strInput Dim strShutdown Do strComputer = (InputBox("Computer name", "Computer Name")) If strComputer <> "" Then
Network & Sharing
Don't want shutdown script to run on restart
Hi, I've got my system configured via gpedit so that it runs a custom batch script when it shuts down. The script can take about a minute to complete because it is telling some external hardware to run through its power down procedure. However when I tell the system to _reboot_ the script...
Software
Is there a way to execute a prgm/script at user logoff/shutdown?
In old WinXP there was a tricky feature in Group Policy editor to execute a script when a User logs off resp. the computer was shutdown. I do not find this feature in Windos 7 (pro). is there another way to execute a *.bat batch script at a) user logoff b) shutdown? Peter
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 02:34.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App