Hello,
I am looking at detecting when I am shutting down the computer so that i can popup a dialog reminding me to do something before I shut down the computer.
ANyone knows how?
Ben
How do I detect when user has chosen to shutdown computer
Moderators: Dorian (MJT support), JRL
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Create a Shut Down macro that pops up a message or runs a routine and then does a shutdown.
Make an icon shortcut for that macro.
Remove the normal Shud Down icon from the Start Menu and replace it by copying the new shortcut onto the Start Menu, labeled ShutDown.
Train people to use the new Start Menu ShutDown icon vs. Start/Shut Down.
The new shutdown routine could include making a log entry to a server shared location. So you can review the logs to see who is not shutting down properly.
=======================
Here is an example of a Shutdown routine that writes to three log files, one for the username, one for the local system, and one for all shutdowns. It also provides to run different batch files depending on the choice of shutdown method. Forced shutdown methods are commented out for later use with a response to a prompt.
Note: This is an old script that may not be current, and may need some work. But it is just an example of what could be done. A similar script is run at Startup to record Logins to the same files and also run batch files based on user/computer ID.
Make an icon shortcut for that macro.
Remove the normal Shud Down icon from the Start Menu and replace it by copying the new shortcut onto the Start Menu, labeled ShutDown.
Train people to use the new Start Menu ShutDown icon vs. Start/Shut Down.
The new shutdown routine could include making a log entry to a server shared location. So you can review the logs to see who is not shutting down properly.
=======================
Here is an example of a Shutdown routine that writes to three log files, one for the username, one for the local system, and one for all shutdowns. It also provides to run different batch files depending on the choice of shutdown method. Forced shutdown methods are commented out for later use with a response to a prompt.
Code: Select all
//Define macro variables
Let>UserPath=F:\PUBLIC\SCRIPTS\Log
Let>UserFile=%USER_NAME%login.LOG
Let>PCPath=F:\PUBLIC\SCRIPTS\Log
Let>PCFile=%COMPUTER_NAME%_login.LOG
Let>NetworkPath=F:\PUBLIC\SCRIPTS\Log
Let>NetworkFile=_login.log
//Need to check for existing paths and files
Let>LogOffPath=F:\BATCH
Let>LogOffFile=LogOff.bat
Let>ReBootPath=F:\BATCH
Let>ReBootFile=ReBoot.bat
Let>ShutDownPath=F:\BATCH
Let>ShutDownFile=ShutDown.bat
//Need to check for existing paths and files
Let>DefaultAction=Log Off
Let>WindowsExit.Action=%DefaultAction%
Let>DefaultReason=Normal-end of work
Let>WindowsExit.Reason=%DefaultAction%
Let>DefaultOther=
//Remove REM to force actions. Need to Prompt to Force Action?
//Let>ForceAction=True
Let>Choice=
Let>RP_WAIT=1
Let>ComboHelp=Log Off allows Log on as a new user.%CRLF%Shut Down turns off power.%CRLF%Re Boot restarts computer
GetDate>Date
GetTime>Time
DayOfWeek>Weekday
Goto>Day%Weekday%
Label>Day1
Let>DOW=Sunday
Goto>Start
Label>Day2
Let>DOW=Monday
Goto>Start
Label>Day3
Let>DOW=Tuesday
Goto>Start
Label>Day4
Let>DOW=Wednesday
Goto>Start
Label>Day5
Let>DOW=Thursday
Goto>Start
Label>Day6
Let>DOW=Friday
Goto>Start
Label>Day7
Let>DOW=Saturday
Goto>Start
Label>Start
Dialog>WindowsExit
Caption=Shut Down Windows
Top=144
Width=315
Left=312
Height=230
Label=What do you want the computer to do?,56,16
Label=%ComboHelp%,34,72
Label=Reason:,21,112
Label=Enter Other Reason / optional Note,125,112
Button=OK,28,160,75,25,1
Button=Cancel,120,160,75,25,2
Button=Help,212,160,75,25,3
ComboBox=Action,82,40,145,%DefaultAction%%CRLF%Re Boot%CRLF%Shut Down
ComboBox=Reason,8,128,121,%DefaultReason%%CRLF%Low Resources%CRLF%Problem noted here:%CRLF%Required by System%CRLF%Software Change%CRLF%System is hung%CRLF%Testing%CRLF%See Other Reason:
Edit=Other,136,128,164,%DefaultOther%
EndDialog>WindowsExit
//Prompt User to select method of Shutdown
Label>ShowWindow
Show>WindowsExit,Button
//Cancelling form will make Button=2
Goto>%Button%
//Help Button
Label>3
//Provide modal instructions
MessageModal>This is a HELP window to explain how this works
Let>DefautlAction=%WindowsExit.Action%
Let>DefautlReason=%WindowsExit.Reason%
Goto>ShowWindow
//Cancel Button
Label>2
Goto>Cancel
//OK Button
Label>1
If>%WindowsExit.Action%=,Errors
If>%WindowsExit.Reason%=,Errors
If>%WindowsExit.Reason%<See>%WindowsExit.Other%=,Errors,Continue
Label>Errors
MessageModal>Missing Action or Reason
Goto>ShowWindow
Label>Continue
Goto>%WindowsExit.Action%
Label>Shut Down
Let>Choice=0
//Forced Shut Down
//Let>Choice=3
//Insert actions to run on Shut Down
WriteLn>%UserPath%\%UserFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Shutting Down computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%PCPath%\%PCFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Shutting Down computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%NetworkPath%\%NetworkFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Shutting Down computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
//Run Program>%ShutDownPath%\%ShutDownFile%
Goto>End
Label>Re Boot
Let>Choice=1
//Forced Re Boot
//Let>Choice=4
//Insert actions to run on Re Boot
WriteLn>%UserPath%\%UserFile%,result,%DOW%, %Date% %Time%:%USER_NAME% ReBooting computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%PCPath%\%PCFile%,result,%DOW%, %Date% %Time%:%USER_NAME% ReBooting computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%NetworkPath%\%NetworkFile%,result,%DOW%, %Date% %Time%:%USER_NAME% ReBooting computer %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
//Run Program>%ReBootPath%\%ReBootFile%
Goto>End
Label>Log Off
Let>Choice=2
//Forced Log Off
//Let>Choice=5
//Insert actions to run on Log Off
WriteLn>%UserPath%\%UserFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Logging Out from %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%PCPath%\%PCFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Logging Out from %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
WriteLn>%NetworkPath%\%NetworkFile%,result,%DOW%, %Date% %Time%:%USER_NAME% Logging Out from %COMPUTER_NAME%.-//-%WindowsExit.Reason% %WindowsExit.Other%.
//Run Program>%LogOffPath%\%LogOffFile%
Goto>End
Label>End
//Messages are for test purposes only
//Added Waits to help troubleshoot Logoff error messages..no change....
If>%ForceAction%<True>Choice=%Choice%+3
Label>End2
Wait>2
//Message> %USER_NAME%, you have decided to %WindowsExit.Action%.%CRLF%Windows will close %COMPUTER_NAME% using Option %Choice%.
Wait>2
//Added Novell Logout to help troubleshoot Logoff error messages..no change....
//Run Program>I:\Public\logout.exe
Wait>2
ShutDownWindows>%Choice%
Label>Cancel
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!