关机功能在使用Windows API时执行注销窗口

时间:2011-01-10 14:46:42

标签: vb.net winapi

我已使用以下代码关闭系统但它将执行注销窗口

Private Const EWX_LogOff = 0  
Private Const EWX_SHUTDOWN = 1  
Private Const EWX_REBOOT = 2  
Private Const EWX_FORCE = 4  

Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Public Sub ShutDownComputer()  
  Call ExitWindowsEx(EWX_FORCE, &HFFFFFFFF)   
End Sub 

3 个答案:

答案 0 :(得分:2)

试试这个

Private Const EWX_POWEROFF = 8 
Call ExitWindowsEx(EWX_POWEROFF, &HFFFFFFFF) 

此链接也可以帮助您

Why simply calling ExitWindowsEx won’t Shutdown/Restart the Computer

答案 1 :(得分:1)

尝试将SHUTDOWN与FORCE结合使用。

答案 2 :(得分:0)

除了Eugene所说的,最好使用pinvoke的声明:

Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Int32, ByVal dwReserved As Int32) As Int32

声明为两个四字节整数的参数(作为dll中的ExitWindowsEx函数)。