# batch file at shutdown not working



## vipulgos (Oct 18, 2009)

Dear all,
This is my first thread on group. please help me
I have a batch file as under:
@Echo Off
ClS
Echo REMOVE PEN DRIVE IF ANY!!
Pause
This has been added at group policy>shutdown part.
at the time of shutting down computer, it shows message that "running shutdown script", but I cant see that message and computer hang with message.
What is wrong i am doing?


----------



## Callum_Dawson (Mar 9, 2009)

It will probably be running as you get the "Windows is shutting down..." menu so you won't see it.


----------



## vipulgos (Oct 18, 2009)

but then what should i do to have that message apeear on the screen. Moreover this shutting down message is running for half an hour..May be more, as I have manually shut down computer after half an hour


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

A shutdown script runs under the System Account, so won't have a visible window, plus when the script is run, the system has already switched to the logon/logoff desktop which would hide it anyway.
A logoff script runs under the Current User's account, but also doesn't have a visible window. I'm guessing it is actually running in a System session (so it won't be visible) but with User permissions.
The pause statement makes it wait for the user to press a key, but since the window isn't visible, it will wait forever.

What you need to do is to call notepad to display a text file with the message.
Give this a try. It creates the text file, displays it for 5 seconds, then deletes it. The ping controls how long the message displays, the time is in milliseconds, so 5000=5 seconds.
If running Vista/Win7 you can use *timeout 5* in place of the ping statement
You may want to run this as a logoff script rather than a shutdown script, so it will display if they just logoff instead of shutdown.

```
@Echo Off
>"%~dp0\Message.txt" Echo REMOVE PEN DRIVE IF ANY!!
Start Notepad.exe "%~dp0\Message.txt"
ping 1.0.0.0 -n 1 -w 5000
Del "%~dp0\Message.txt"
```


----------



## vipulgos (Oct 18, 2009)

This vb script is working. It shows the message window at the shutdown. Thanks for ur help.

Dim MyVar

MyVar = MsgBox ("Remove pen drive if any", 0, "Vipul's message")


----------



## TheOutcaste (Aug 8, 2007)

You're welcome, thanks for posting your solution.

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post) 










Jerry


----------

