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) ' 控制台收到那些消息 ' 0- CTL C ' 1- CTL + Break ' 2- CLOSE,可能是通过关闭close按钮也可能是直接关闭进程 ' 3- 操作系统要注销 ' 4- 系统要关机 'Add Your Log End Sub End Module