#150781 - 2005-10-28 09:11 PM
Re: Detect OS/Service shutdown in a loop
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
I don't think KiX can do it natively but a KiXform might be able to, or Shawn might be able to add that as a feature.
WM_QUERYENDSESSION is what is sent to all applications, but no way for KiX to get that and let you know.
Here is an article for Shawn if it needs to go that way.
Making a Windows Forms app respond to System Shutdown http://www.stevex.org/cs/blogs/dottext/articles/155.aspx
|
|
Top
|
|
|
|
#150785 - 2005-11-08 11:26 AM
Re: Detect OS/Service shutdown in a loop
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
I'd hate to scan a file or use a file as a semaphore, but I'm not seeing any other options... Any ideas out there?
I'm not too sure what you are asking for - you might need to explain a little more.
If you are just looking for a way that two process can communicate without using a file then two methods spring to mind.
- Use the registry. The two scripts agree on a sub-key or value and then use it to communicate. This is excellect for two-way communication, especially when you need a high degree of handshaking.
- Execute a process with fixed option values. Excellent if you don't want to leave any traces, but much harder to code and may only be supportable with XP and 2003.
The first option is an obvious method and very easy. The second option is a little more complicated.
The way it works is simple. In the "talking" script you run a command like: Code:
Shell '"'+%COMSPEC%+'" /C "SLEEP 9999 && REM IPC: Some Message'
In the "listening" script you do: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") Dim $oWMI,$oProcess,$oProcesses,$iQuit,$sMessage Dim $sSentinel,$iTerminate $sSentinel="REM IPC: " $oWMI=GetObject("Winmgmts:{impersonationLevel=impersonate}") While Not $iQuit Sleep $iTerminate $iTerminate=0 ; Give terminated processes a change to close. $oProcesses=$oWMI.ExecQuery('Select CommandLine from Win32_Process') If @ERROR "2 " @ERROR " " @SERROR ? EndIf For Each $oProcess in $oProcesses If InStr($oProcess.CommandLine,$sSentinel) $sMessage=$oProcess.CommandLine $sMessage=SubStr($sMessage,InStr($sMessage,$sSentinel)+Len($sSentinel)) Select Case $sMessage="QUIT" $iQuit=1 Case "Not handled" "Unhandled message from talker: "+$sMessage+@CRLF EndSelect $=$oProcess.Terminate $iTerminate=2 EndIf Next Loop Exit 0
Now, you can tidy up the select clause and improved the wait for the terminated process, but I'm sure that you get the idea.
If you abstract the "talk" and "listen" processes into functions it makes the whole thing fairly easy.
The only drawback is that "CommandLine" may not be universally supported.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1452 anonymous users online.
|
|
|