2014-05-22 9 views
0

AutoIT를 사용하여 시스템이 종료되거나 로그 오프되는 것을 어떻게 감지합니까? 기본적으로 스크립트가 실행되는 동안 컴퓨터가 종료되거나 로그 오프되면 함수를 실행해야합니다.시스템 종료 또는 로그 오프 감지

정말 감사드립니다.

감사합니다.

답변

3

당신은 메시지를 WM_QUERYENDSESSION

샘플 코드를 처리해야합니다

$WM_QUERYENDSESSION = 0x11 ; Define the Variable for the Message 

; Register a Callback on the Message to the Function "onShutDown" 
GUIRegisterMsg($WM_QUERYENDSESSION, "onShutDown") 


Func onShutDown($hWndGUI, $MsgID, $WParam, $LParam) 
    Return True ; Return True to allow Shutdown or False to prevent Shutdown 
EndFunc 
2

당신은 또한 PC가 종료되어 있다고 가정 할 수 있습니다 같은 방법으로 OnAutoItExitRegister을 구현할 수 있습니다.

 OnAutoItExitRegister("DetectShutdown") 

     GUICreate("My GUI") ; will create a dialog box that when displayed is centered 
     GUISetState(@SW_SHOW) ; will display an empty dialog box 

     ; Run the GUI until the dialog is closed 
     While True 
      $msg = GUIGetMsg() 

      If $msg = $GUI_EVENT_CLOSE Then 
        OnAutoItExitUnRegister("DetectShutdown") 
        Exit 
      EndIf 
     WEnd 

      Func DetectShutdown() 

         MsgBox(0,"","Shutdown Detected!") 

      EndFunc 
+0

"그런 식으로"? 실천 사례도 제공해 주실 수 있습니까? – Samoth

+0

GUI를 종료 할 때 코드에서 OnAutoItExitUnregister를 호출해야합니다. 그렇게하면 시스템이 앱 종료를 시도 할 때 OnAutoItExitRegister로 등록 된 함수가 호출됩니다. – Milos

+0

@Samoth 예제 코드가 추가되었습니다. – Milos