PRivate void HookSessionEnding() 

{ 
Microsoft.Win32.SystemEvents.SessionEnding += 
new Microsoft.Win32.SessionEndingEventHandler(this.OnSessionEnding); 
} 
private void OnSessionEnding( object sender, 
Microsoft.Win32.SessionEndingEventArgs e ) 

{ 
    // the user session is ending 
} 
Module Module1Module Module1  
    Public Declare Function SetConsoleCtrlHandler()Function SetConsoleCtrlHandler Lib "kernel32.dll" Alias "SetConsoleCtrlHandler" (ByVal handlerRoutine As HandlerRoutine, ByVal add As Boolean) As Boolean  
    Public Delegate Sub HandlerRoutine()Sub HandlerRoutine(ByVal type As Integer)  
 
    Sub Main()Sub Main() 
 
        SetConsoleCtrlHandler(AddressOf MyHandle, True)  
        Console.ReadLine()  
 
    End Sub 
 
    Public Sub MyHandle()Sub MyHandle(ByVal type As Integer)  
        ' 控制臺(tái)收到那些消息  
        ' 0- CTL C  
        ' 1- CTL + Break  
        ' 2- CLOSE,可能是通過關(guān)閉close按鈕也可能是直接關(guān)閉進(jìn)程  
        ' 3- 操作系統(tǒng)要注銷  
        ' 4- 系統(tǒng)要關(guān)機(jī)  
 
        'Add Your Log  
    End Sub  
 
End Module  
 新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注