Jump to content

Does Windows Have a Place for Calling Programs to Run at Shutdown?


Zohar
 Share

Recommended Posts

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 by Zohar
Link to comment
Share on other sites

#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 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

  • Developers

@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 by Jos

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

Link to comment
Share on other sites

  • Zohar changed the title to Does Windows Have a Place for Calling Programs to Run at Shutdown?

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 by Zohar
Link to comment
Share on other sites

  • Developers
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...