4个回答
2013-11-09
展开全部
呵呵 给你一个只能关xp/2003的简单代码
dim i as integer
i=shell("cmd /c shutdown -t 00 -s",vbhide)
dim i as integer
i=shell("cmd /c shutdown -t 00 -s",vbhide)
2013-11-09
展开全部
使用API函数
Exitwindows 1,1关机
exitwindows 2,1重启
ExitWindows 0,1注消
16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。
Exitwindows 1,1关机
exitwindows 2,1重启
ExitWindows 0,1注消
16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-09
展开全部
以下只适用于XP最好用Api实现
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function ExitWindowsEx Lib "USER32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Enum EXITWINDOWSEXENUM
EWX_LogOff = 0
EWX_SHUTDOWN = 1
EWX_REBOOT = 2
EWX_FORCE = 4
EWX_POWEROFF = 8
End Enum
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function ExitWindowsEx Lib "USER32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Enum EXITWINDOWSEXENUM
EWX_LogOff = 0
EWX_SHUTDOWN = 1
EWX_REBOOT = 2
EWX_FORCE = 4
EWX_POWEROFF = 8
End Enum
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-09
展开全部
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
'判断此系统是否为NT系统的函数
Private Function NT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
NT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
End Function
'取得NT下的关机的权限
Private Sub EnableShutDown()
Dim lProc As Long
Dim lToken As Long
Dim lLUID As LUID
Dim tPriv As TOKEN_PRIVILEGES
Dim tNewPriv As TOKEN_PRIVILEGES
Dim buffer As Long
lProc = GetCurrentProcess()
OpenProcessToken lProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lToken
LookupPrivilegeValue "", "SeShutdownPrivilege", lLUID
tPriv.PrivilegeCount = 1
tPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
tPriv.Privileges(0).pLuid = lLUID
AdjustTokenPrivileges lToken, False, tPriv, Len(tNewPriv), tNewPriv, buffer
End Sub
'首先调用判断OS的函数,如为NT则调用NT下的关机函数,而9x系统中可直接调用ExitWindowsEx函数
Private Sub Command1_Click()
Dim flags As Long
flags = EWX_SHUTDOWN + EWX_FORCE
If NT Then
EnableShutDown
ExitWindowsEx flags, 0
Else
ExitWindowsEx flags, 0
End If
End Sub
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
'判断此系统是否为NT系统的函数
Private Function NT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
NT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
End Function
'取得NT下的关机的权限
Private Sub EnableShutDown()
Dim lProc As Long
Dim lToken As Long
Dim lLUID As LUID
Dim tPriv As TOKEN_PRIVILEGES
Dim tNewPriv As TOKEN_PRIVILEGES
Dim buffer As Long
lProc = GetCurrentProcess()
OpenProcessToken lProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lToken
LookupPrivilegeValue "", "SeShutdownPrivilege", lLUID
tPriv.PrivilegeCount = 1
tPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
tPriv.Privileges(0).pLuid = lLUID
AdjustTokenPrivileges lToken, False, tPriv, Len(tNewPriv), tNewPriv, buffer
End Sub
'首先调用判断OS的函数,如为NT则调用NT下的关机函数,而9x系统中可直接调用ExitWindowsEx函数
Private Sub Command1_Click()
Dim flags As Long
flags = EWX_SHUTDOWN + EWX_FORCE
If NT Then
EnableShutDown
ExitWindowsEx flags, 0
Else
ExitWindowsEx flags, 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询