110,566
社区成员
发帖
与我相关
我的任务
分享
Option Compare Binary
Option Explicit On
Option Strict On
Public Class clShutdown
Public Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Boolean
Public Declare Function NtShutdownSystem Lib "ntdll" (ByVal ShutdownAction As enumntshutdownsystem) As Integer
Public Declare Function RtlAdjustPrivilege Lib "ntdll" (ByVal Privilege As Integer, ByVal NewValue As Integer, ByVal NewThread As Integer, ByRef OldValue As Integer) As Integer
Public Const SE_SHUTDOWN_PRIVILEGE As Integer = 19
Enum enumntshutdownsystem As Integer
shutdown = 0
RESTART = 1
POWEROFF = 2
End Enum
Enum enumexitwindowsflags As Integer
EWX_LOGOFF = 0
EWX_SHUTDOWN = 1
EWX_REBOOT = 2
EWX_FORCE = 4
EWX_POWEROFF = 8
EWX_FORCEIFHUNG = 10
End Enum
Public Sub TurboShutdown(ByVal turbo As enumntshutdownsystem)
Try
RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, 1, 0, 0)
NtShutdownSystem(turbo) '关机
'NtShutdownSystem restart '重启动
'NtShutdownSystem poweroff '关机
Catch ex As Exception
End Try
End Sub
Public Sub simshutdown(ByVal sim As enumexitwindowsflags)
Try
Dim b As Boolean
RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, 1, 0, 0)
b = ExitWindowsEx(sim, 0)
Catch ex As Exception
End Try
End Sub
End Class
很久之前用vb.net写的一个。你找个在线翻译的。翻译成c#吧。