AutoHotkey Community

It is currently May 27th, 2012, 12:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: October 6th, 2005, 2:40 am 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
Is there a way I can temporarilly suspend a shutdown or logoff initiated from the start button from within AHK? I want my script to run a backup program (takes 15-30 seconds) before the shutdown. I can sometimes get the backup going using OnExit but the normal windows shutdown process continues on and kills it. Other times it won't even start because windows is shutting down. Seems to be a timing issue.

What I'd like to do is something like this...
Code:
OnExit,OnExitRoutine

OnExitRoutine:
  If A_ExitReason in Logoff,Shutdown
  {
    ; Suspend logoff/shutdown process somehow???
    Shutdown,-1 ; just a suggestion for syntax
    ; Do the backup
    RunWait,C:\Program Files\....
    ; Resume logoff/shutdown process
    If A_ExitReason = Logoff
      Shutdown,0
    If A_ExitReason = Shutdown
      Shutdown,1
  }
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2005, 4:53 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Below is a script that comes close. The main problem is that on Windows NT/2000/XP, a shutdown/logoff causes applications to begin to close immediately (the order of closure might be in reverse order of startup but I'm not sure if this can be relied upon). Consequently, if your backup program is not designed to abort the shutdown, it may close in the middle of its operation before the script has a chance to abort the shutdown.

Anyway, the following is a working demonstration script.
Code:
#Persistent
OnMessage(0x11, "WM_QUERYENDSESSION")
return

WM_QUERYENDSESSION(wParam, lParam)
{
   ENDSESSION_LOGOFF = 0x80000000
   if (lParam & ENDSESSION_LOGOFF)  ; User is logging off.
      EventType = Logoff
   else  ; System is either shutting down or restarting.
      EventType = Shutdown
   MsgBox, 4,, %EventType% in progress.  Allow it?
   IfMsgBox, YES
      return true  ; Tell the OS to allow the shutdown/logoff to continue.
   else
      return false  ; Tell the OS to abort the shutdown/logoff.
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2005, 5:16 pm 
Offline

Joined: June 24th, 2004, 1:00 am
Posts: 114
Location: Malta
Hi!
No need to go through all that.
This is how I do these Logon/Off Jobs.

Prepare your script/Program (whatevever you want to run)
Start Group policy --- at the run command (Start - Run) type gpedit.msc
Open User Configuration then window settings.
Then Scripts (Logon/Logoff)
Click on Logoff Click Properties

Add whatever you want to run here (can also take parameters)

That's it

Can be used for users or system both On and Off

Hope this helps

bahri


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2006, 12:18 pm 
Offline

Joined: November 12th, 2005, 10:25 pm
Posts: 73
Sorry reviving this Topic, but I'm interested in doing this, Pausing the logOff and Shutdown of Windows...

The problem is:
the lParam onlyd etects if the windows is logging off or ShutingDown. What about Restarting?
I have a script that has to run for about 5secs after shuttingdown. So I use that on massage and imediatly return False. But then I send a shutdown command... At that time I can't know If I was shuttingdown or restarting :S

Any Ideas?

Code:
#persistent
OnMessage(0x11, "WM_QUERYENDSESSION")
return

WM_QUERYENDSESSION(wParam, lParam)
{
    global lpar
    lpar=%lParam%
    settimer, ps_loggingoff, 100, 9999
    return false
}
return

ps_loggingoff:

(about 5 Secs long)

if lPar
    shutdown, 0
else
    shutdown, 1
exitapp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2006, 2:20 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I seem to remember that this part of the API provides no means of distinguishing between Shutdown and Restart. There may be some other way to detect it, but I don't know it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2006, 8:23 am 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Hi,

is there a way to add/remove a logon-script with AutoHotkey? I've XP Home which does not have gpedit.msc.

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2006, 8:48 am 
Offline

Joined: September 24th, 2004, 3:00 pm
Posts: 814
Location: Germany
Hi,

I've found something here: http://www.snugserver.com/phpbb2/viewto ... highlight=

But how to get the SID in AutoHotkey?

Code:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-777546997-2006763630-3948032881-1108\Scripts\Logoff\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-777546997-2006763630-3948032881-1108\Scripts\Logoff\0\0]
"Script"="C:\\test.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

_________________
Tekl


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav, MSN [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group