Zohar Posted December 25, 2021 Share Posted December 25, 2021 (edited) Hi all I need a small script to run every time the computer is Shut Down (or Restarted). While for Starting there's the known CurrentVersion\Run registry key, Is there something also for running a program just before Shutdown/Restart? Thank you Edited December 26, 2021 by Zohar Link to comment Share on other sites More sharing options...
ad777 Posted December 25, 2021 Share Posted December 25, 2021 (edited) #include <AutoItConstants.au3> OnAutoItExitRegister("_call") #cs 0 = Natural closing. 1 = close by Exit function. 2 = close by clicking on exit of the systray. 3 = close by user logoff. 4 = close by Windows shutdown Or Restart(same) #ce While 1 WEnd Func _call() if @exitMethod = 4 Then MsgBox(0,'','exit by shurdown||Restart');;exit by shutdown Or Restart EndIf EndFunc Edited December 25, 2021 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 25, 2021 Developers Share Posted December 25, 2021 (edited) @ad777, I assume the idea is to run this script at startup, as you haven't stated anything on how to use it, and the _call() function will become active when a Windows message is received to Shutdown/Restart, but you never want to have a close loop without any form of pausing in it, so this script will probably max out at least 1 CPU core 100% of the time. I've also provided a Tidy.exe option in the Full version of SciTE4AutoIt3, so would recommend to always run in before posting code here, so all looks readable. Adapted version: #include <AutoItConstants.au3> OnAutoItExitRegister("_shutdown") #cs 0 = Natural closing. 1 = close by Exit function. 2 = close by clicking on exit of the systray. 3 = close by user logoff. 4 = close by Windows shutdown Or Restart(same) #ce While 1 Sleep(100) WEnd Func _shutdown() If @exitMethod = 4 Then MsgBox(0, '', 'exit by shurdown||Restart') ;;exit by shutdown Or Restart EndIf EndFunc ;==>_shutdown Merry Christmas. Edited December 25, 2021 by Jos ad777 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted December 25, 2021 Share Posted December 25, 2021 Instead of having a script running all the time, you could create a task in task scheduler that is launch when user logs off (happens when shutdown). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Zohar Posted December 26, 2021 Author Share Posted December 26, 2021 (edited) Thank you all. The purpose of this script it to Log. So the script does not have to run the whole Windows Session, only 1 second during Shutdown/Restart. Using OnAutoItExitRegister() indeed was an option, yet I prefer something by Windows, that happens during Shutdown, that way the script does not have to run the whole session, waiting for the Windows session to end.. 18 hours ago, Nine said: Instead of having a script running all the time, you could create a task in task scheduler that is launch when user logs off (happens when shutdown). That's a nice option, I might indeed use it. BTW, is there maybe a Registry option too? Similar to CurrentVersion\Run, just for Shutdown instead of Starting? Edited December 26, 2021 by Zohar Link to comment Share on other sites More sharing options...
Developers Jos Posted December 26, 2021 Developers Share Posted December 26, 2021 16 minutes ago, Zohar said: BTW, is there maybe a Registry option too? Similar to CurrentVersion\Run, just for Shutdown instead of Starting? Did you try to search for the answer and found anything? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zohar Posted December 26, 2021 Author Share Posted December 26, 2021 (edited) You're right.. Searching for windows registry run at shutdown indeed gives relevant results. I will try it now, thank you. Edited December 26, 2021 by Zohar Werty 1 Link to comment Share on other sites More sharing options...
levila Posted December 30, 2021 Share Posted December 30, 2021 i think you should check on GPEDIT Computer Policy > Windows Settings > Script (Shutdown) This method will run script whenever you shutdown. Zohar and CarlD 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now