Jump to content

Messaging


anixon
 Share

Recommended Posts

I have lifted this code example from the forum but have been unable to make it work in a Windows Vista Environment

Global $WM_QUERYENDSESSION = 0x0011
Func InterceptShutdown($hWnd, $msg, $w, $l) 
 IniWrite(@ScriptDir & "\test.ini", "Test", "Value", "Shutdown")
EndFunc   ;==>InterceptShutdown
GUIRegisterMsg($WM_QUERYENDSESSION, "InterceptShutdown")
While 1
 MsgBox(0, "", "Idling", 1)
WEnd

Any assistance would be greatly appreciated Ant.. :x

Link to comment
Share on other sites

I have also tried this code posted elsewhere in this forum but it does not work either

DllCall("kernel32.dll", "int", "SetProcessShutdownParameters", "long", 0x3FF, "long", 0) ;makes this program get a "Shutdown" message before other programs, but after the system
While 1
    Sleep(1000)
WEnd

Func OnAutoItExit()
    If @ExitMethod = 4 Then Whatever() ; shutting down, do something
EndFunc

Func Whatever()
 IniWrite(@ScriptDir & "\test.ini", "Test", "Shutdown", "Worked")
    ; do whatever it is you want to do here, before most of the programs get shut down
    ; make sure you do not take too long because the system will attempt to close this if it goes past the normal "program shutdown time"
EndFunc
Link to comment
Share on other sites

Umm couldn't you just go to

Start=>Run=> Then type in cmd=>Then type Shutdown -a?

Thanks for that I don't want to force a shutdown I just want the alert when a shutdown occurs. I have just established the program that runs the shutdown and have written this code which whilst it is not the elegant appears to work

While 1
If ProcessExists("RUNDLL32.EXE") Then
  IniWrite(@ScriptDir & "\test.ini", "Test", "Shutdown", "Worked")
EndIf
Sleep(100)
WEnd

This code does not work either RUNDLL32.exe might be associated with Shutdown but I dont believe that it is exclusive to that process Ant..

Edited by anixon
Link to comment
Share on other sites

Thanks for that I don't want to force a shutdown I just want the alert when a shutdown occurs. I have just established the program that runs the shutdown and have written this code which whilst it is not the elegant appears to work

While 1
 If ProcessExists("RUNDLL32.EXE") Then
  IniWrite(@ScriptDir & "\test.ini", "Test", "Shutdown", "Worked")
 EndIf
 Sleep(100)
WEnd

What I provided does not force a shutdown, it Aborts it. shutdown -A(bort)

You can do some cool things with this code.

Examples:

Open up notepad and type this in:

Shutdown -s -t 2 -c "This will shutdown your computer"

Then save it as a .bat file and if you double click it it will shutdown :x

Link to comment
Share on other sites

What I provided does not force a shutdown, it Aborts it. shutdown -A(bort)

You can do some cool things with this code.

Examples:

Open up notepad and type this in:

Shutdown -s -t 2 -c "This will shutdown your computer"

Then save it as a .bat file and if you double click it it will shutdown :x

I can see the power of this routine but what I want to be able to do is to trigger a script to run on a Scheduled or Unexpected Windows /Shutdown unexpected shutdown. This is a shortcut to Windows Vista Shutdown http://msdn.microsoft.com/en-us/library/ms700677.aspx

Help in relation to this process would be appreciated. Ant..

Edited by anixon
Link to comment
Share on other sites

I can see the power of this routine but what I want to be able to do is to trigger a script to run on a Scheduled or Unexpected Windows /Shutdown unexpected shutdown. This is a shortcut to Windows Vista Shutdown http://msdn.microsoft.com/en-us/library/ms700677.aspx

Help in relation to this process would be appreciated. Ant..

Thanks to everyone for the help in particular Richard Robertson who pointed me in the right direction. This is the code that I have developed that monitors for an expected and unexpected shutdown.

;//Process an Unexpected Shutdown
OnAutoItExitRegister("_ForcedShutdown")

;//Includes Date Time Processing
#include <Date.au3>

;//Global Variables
Global $Title = "YourName", $sMyProgramExe = @ScriptDir & "\MyProgram.exe", $sShutdownINI = @ScriptDir & "\Shutdown.ini"

;//Run the Monitor
While 1
;//Runs when sMyProgramExe is Running
If Not ProcessExists($sMyProgramExe) Then Exit
Sleep(50)
WEnd

;//Forced Shutdown Routine
Func _ForcedShutdown()
If @ExitMethod = 0 Then $SysMessage = $Title & " Unexpected Close "
If @ExitMethod = 1 Then $SysMessage = $Title & " Closed by Exit Function"
If @ExitMethod = 2 Then $SysMessage = $Title & " Closed by System Tray Exit"
If @ExitMethod = 3 Then $SysMessage = $Title & " Closed by User Logoff"
If @ExitMethod = 4 Then $SysMessage = $Title & " Closed by Windows Shutdown"
IniWrite($sShutdownINI, "Windows", "Shutdown ["& @ExitMethod & "]",  $Title & " " & _DateTimeFormat(_NowCalc(), 0))
If ProcessExists($sMyProgramExe) Then ProcessClose($sMyProgramExe)
OnAutoItExitUnRegister("_ForcedShutdown")
Exit
EndFunc
Edited by anixon
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...