Run Macro On Windows Shut Down - MS v6.2

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Run Macro On Windows Shut Down - MS v6.2

Post by CyberCitizen » Mon Jan 10, 2005 6:40 am

Hello,

Our company has purchased Macro Scheduler v6.2, which works great.

The issue I face is that I want to run a Macro on Windows shut down. Eg. Halt Windows shutdown until macro finished.

Note that part of the macro will involve user input. Eg we have a server that we use to clock on & off with. Clock on is easy as it starts with windows, however people are failing to clock off.

If I can right a macro to run on shutdown & wait user input before shutting down windows that would be great.

Note the company does not want to pay for the upgrade to version 7x as they believe that they have paid for the software & shouldn't have to pay again. So no VB support guys sorry.
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Jan 10, 2005 2:29 pm

I submitted this in June 2004. Perhaps it will help:
=======================================

Posted: Sat Jun 19, 2004 12:01 am Post subject: Reply with quote Edit/Delete this post
This is a script that I have not reviewed since it was "done" about 18 months ago. Definitely still has some unfinished bricks in place, that's how it goes, lots of unfulfilled plans.. No time right now to clean it up for you, all the extra garbage is free.

Code: Select all

//Define macro variables
//Logging out is writtten to three logs: 1 for each user, one for each computer, and one for entire network.
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


//Provide ability to modify each logoff without changing compiled Macro Scheduler.
//May be different for Logoff, reboot, or shutdown...handles all.
//Just create Batch files that are called before Logout happens.
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?
//Should add this decision to Dialog box in future....Force Actiion?
//Let>ForceAction=True

Let>Choice=
Let>RP_WAIT=1
//Let>MSG_STAYONTOP=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
//This is beginning of Dialog to Logoff, Reboot, Shutdown
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
//Some conditions require entry in Reason field, some don't.force if empty.
If>%WindowsExit.Action%=,Errors
If>%WindowsExit.Reason%=,Errors
If>%WindowsExit.Reason%<>See Other Reason:,Continue
If>%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

//NOTES=====================================
//Need default value for Combo box
//Need Combo Help window to change based on ComboBox value
//Closing Dialog with "X" continues macro, need to add notes to Help about where that continues.
//Closing with "X" is same as Button=2?
//Closing with "X" keeps values of variables, such as combo box
//Line pointer stays at Dialog line
//Need library of Dialogs
//Edit/Memo box not available if no initial value
//Sensitive help not available on Dialog object lines, only on Dialog
//Combo Box needs user defined at time of use...not in list.
//Combo Box Ability to modify existing value
//If need to reshow Dialog, how to keep values already entered?
//Need Message Box on top to see message box.
//Cannot respond to Message Box from Dialog, even with Message on Top

//No indication that horizontal scroll bar will show up on Dialog
//Need to see outline of Label box.on form while designing.

Label>End
//Messages are for test purposes only
//Added Waits to help troubleshoot Logoff error messages..no change....
If>%ForceAction%<>True,End2
Let>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

There are certainly areas to be improved, and still need to activate the Run Program sections, but may never get to them. This is working adequately for now.

If you Cut/Paste from the forum, be sure to use the tools in the Editor to remove Trailing Spaces. Click on Edit, Show All Characters, and Remove Trailing Spaces.
_________________
====================================
1/10/06: I have since modified this and removed LogOff and Shutdown from the start menu, replacing them with a LogOff icon that calls the revised compiled script.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Jan 18, 2005 4:09 am

Hello Bob,

Thank you for your script. It looks like you spend a little bit of time on it.

Is looks quite a busy script. Was looking for something a little easier.

Thanks for your help.
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jan 18, 2005 6:54 am

Stripped down version (untested, stripped code on the fly):

Code: Select all

//Define macro variables
Let>Choice=
Let>DefaultAction=Log Off

Label>Start
//This is beginning of Dialog to Logoff, Reboot, Shutdown
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
Button=OK,28,160,75,25,1
Button=Cancel,120,160,75,25,2
ComboBox=Action,82,40,145,%DefaultAction%%CRLF%Re Boot%CRLF%Shut Down
EndDialog>WindowsExit

//Prompt User to select method of Shutdown
Label>ShowWindow
Show>WindowsExit,Button
//Cancelling form will make Button=2
Goto>%Button%

//Cancel Button
Label>2
Goto>Cancel

//OK Button
Label>1
If>%WindowsExit.Action%=,Errors,Continue

Label>Errors
MessageModal>Missing Action
Goto>ShowWindow

Label>Continue
Goto>%WindowsExit.Action%

Label>Shut Down
Let>Choice=0
Goto>End

Label>Re Boot
Let>Choice=1
Goto>End

Label>Log Off
Let>Choice=2
Goto>End

Label>End
ShutDownWindows>%Choice%

Label>Cancel
This will be a better starting structure to start with and modify as needed..
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Lumumba

Post by Lumumba » Tue Jan 18, 2005 11:57 am

Bob,
I still love your sig-image :lol:

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jan 18, 2005 10:49 pm

And MOM is so proud too! Shows it off to everyone. :lol:
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts