try thisOption ExplicitPrivate Const TOKEN_ADJUST_PRIVILEGES = &H20 Private Const TOKEN_QUERY = &H8 Private Const SE_PRIVILEGE_ENABLED = &H2 Private Const EWX_SHUTDOWN As Long = 1 Private Const EWX_FORCE As Long = 4 Private Const EWX_REBOOT = 2 Private Type LUID UsedPart As Long IgnoredForNowHigh32BitPart As Long End TypePrivate Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type'关闭系统的API Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, _ ByVal dwReserved As Long) As Long '获取当前进程的一个伪句柄 '只要当前进程需要一个进程句柄,就可以使用这个伪句柄。该句柄可以复制,但不可继承。不必调用CloseHandle函数来关闭这个句柄 Private Declare Function GetCurrentProcess Lib "kernel32" () As Long'以下为NT/2000中和权限相关的函数 '如果函数执行成功,返回非零。 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 Sub ExitSystem() Dim hProcessHandle As Long Dim hTokenHandle As Long Dim tmpLuid As LUID Dim tkpNew As TOKEN_PRIVILEGES Dim tkpPrevious As TOKEN_PRIVILEGES Dim lBufferNeeded As Long hProcessHandle = GetCurrentProcess() Call OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle) Call LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid) tkpNew.PrivilegeCount = 1 tkpNew.TheLuid = tmpLuid tkpNew.Attributes = SE_PRIVILEGE_ENABLED lBufferNeeded = 0 Call AdjustTokenPrivileges(hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded) Call ExitWindowsEx(EWX_SHUTDOWN, &O0)End Sub
or this ---------------------------------------------------------------------- 退出操作系统可以调用Windows API的ExitWindowsEx函数。 例子: 1、建立一个窗体,在上面放置4个按钮,按钮设置如下: 控件 控件名 Caption属性 --------------------------------------------------- CommandButton cmdLogoff 注销 CommandButton cmdForceLogoff 强制注销 CommandButton cmdShutdown 关机 CommandButton cmdForceShutdown 强制关机 2、将下面的代码加入窗体中: Option Explicit Private Const EWX_LogOff As Long = 0 Private Const EWX_SHUTDOWN As Long = 1 Private Const EWX_REBOOT As Long = 2 Private Const EWX_FORCE As Long = 4 Private Const EWX_POWEROFF As Long = 8
'The ExitWindowsEx function either logs off, shuts down, or shuts 'down and restarts the system. Private Declare Function ExitWindowsEx Lib "user32" _ (ByVal dwOptions As Long, _ ByVal dwReserved As Long) As Long
'The GetLastError function returns the calling thread's last-error 'code value. The last-error code is maintained on a per-thread basis. 'Multiple threads do not overwrite each other's last-error code. Private Declare Function GetLastError Lib "kernel32" () As Long
'The GetVersion function returns the operating system in use. Private Declare Function GetVersion Lib "kernel32" () As Long
Private Type LUID UsedPart As Long IgnoredForNowHigh32BitPart As Long End Type
Private Type LUID_AND_ATTRIBUTES TheLuid As LUID Attributes As Long End Type
Private Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As Long End Type
'The GetCurrentProcess function returns a pseudohandle for the 'current process. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
'The OpenProcessToken function opens the access token associated with 'a process. Private Declare Function OpenProcessToken Lib "advapi32" _ (ByVal ProcessHandle As Long, _ ByVal DesiredAccess As Long, _ TokenHandle As Long) As Long
'The LookupPrivilegeValue function retrieves the locally unique 'identifier (LUID) used on a specified system to locally represent 'the specified privilege name. Private Declare Function LookupPrivilegeValue Lib "advapi32" _ Alias "LookupPrivilegeValueA" _ (ByVal lpSystemName As String, _ ByVal lpName As String, _ lpLuid As LUID) As Long
'The AdjustTokenPrivileges function enables or disables privileges 'in the specified access token. Enabling or disabling privileges 'in an access token requires TOKEN_ADJUST_PRIVILEGES access. 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 Sub SetLastError Lib "kernel32" _ (ByVal dwErrCode As Long)
Private Sub AdjustToken()
'******************************************************************** '* This procedure sets the proper privileges to allow a log off or a '* shut down to occur under Windows NT. '********************************************************************
Dim hdlProcessHandle As Long Dim hdlTokenHandle As Long Dim tmpLuid As LUID Dim tkp As TOKEN_PRIVILEGES Dim tkpNewButIgnored As TOKEN_PRIVILEGES Dim lBufferNeeded As Long
'Set the error code of the last thread to zero using the 'SetLast Error function. Do this so that the GetLastError 'function does not return a value other than zero for no 'apparent reason. SetLastError 0
'Use the GetCurrentProcess function to set the hdlProcessHandle 'variable. hdlProcessHandle = GetCurrentProcess()
If GetLastError <> 0 Then MsgBox "GetCurrentProcess error==" & GetLastError End If
OpenProcessToken hdlProcessHandle, _ (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
If GetLastError <> 0 Then MsgBox "OpenProcessToken error==" & GetLastError End If
'Get the LUID for shutdown privilege LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
If GetLastError <> 0 Then MsgBox "LookupPrivilegeValue error==" & GetLastError End If
tkp.PrivilegeCount = 1 ' One privilege to set tkp.TheLuid = tmpLuid tkp.Attributes = SE_PRIVILEGE_ENABLED
'Enable the shutdown privilege in the access token of this process AdjustTokenPrivileges hdlTokenHandle, _ False, _ tkp, _ Len(tkpNewButIgnored), _ tkpNewButIgnored, _ lBufferNeeded
If GetLastError <> 0 Then MsgBox "AdjustTokenPrivileges error==" & GetLastError End If
Private Sub cmdForceShutdown_Click() If glngWhichWindows32 = mlngWindowsNT Then AdjustToken MsgBox "Post-AdjustToken GetLastError " & GetLastError End If
Private Sub Form_Load() '******************************************************************** '* When the project starts, check the operating system used by '* calling the GetVersion function. '******************************************************************** Dim lngVersion As Long
lngVersion = GetVersion()
If ((lngVersion And &H80000000) = 0) Then glngWhichWindows32 = mlngWindowsNT MsgBox "Running Windows NT or Windows 2000" Else glngWhichWindows32 = mlngWindows95 MsgBox "Running Windows 95/98/Me" End If
End Sub
3、编译成EXE,然后退出VB运行该EXE程序
简单的说 Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPrivate Sub Command1_Click(Index As Integer) Select Case Index Case 0 i = ExitWindowsEx(EWX_FORCE, 0) ' 强迫中止没有响应的进程 Case 1 i = ExitWindowsEx(EWX_REBOOT, 0) '重新引导系统 Case 2 i = ExitWindowsEx(EWX_SHUTDOWN, 0) '关闭系统 End Select End Sub 先建索引command按钮,应该简单吧
在WIN2K下隐藏进程的难度非常的大。
建议看 罗云彬写的《WINDOWS环境下32位汇编语言程序设计》上面有详细的解说。也可去他的网站
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_FORCE As Long = 4
Private Const EWX_REBOOT = 2
Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End TypePrivate Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type'关闭系统的API
Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long
'获取当前进程的一个伪句柄
'只要当前进程需要一个进程句柄,就可以使用这个伪句柄。该句柄可以复制,但不可继承。不必调用CloseHandle函数来关闭这个句柄
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long'以下为NT/2000中和权限相关的函数
'如果函数执行成功,返回非零。
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
Sub ExitSystem() Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim tmpLuid As LUID
Dim tkpNew As TOKEN_PRIVILEGES
Dim tkpPrevious As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long hProcessHandle = GetCurrentProcess()
Call OpenProcessToken(hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle) Call LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid) tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED lBufferNeeded = 0
Call AdjustTokenPrivileges(hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded) Call ExitWindowsEx(EWX_SHUTDOWN, &O0)End Sub
----------------------------------------------------------------------
退出操作系统可以调用Windows API的ExitWindowsEx函数。
例子:
1、建立一个窗体,在上面放置4个按钮,按钮设置如下:
控件 控件名 Caption属性
---------------------------------------------------
CommandButton cmdLogoff 注销
CommandButton cmdForceLogoff 强制注销
CommandButton cmdShutdown 关机
CommandButton cmdForceShutdown 强制关机
2、将下面的代码加入窗体中:
Option Explicit
Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_REBOOT As Long = 2
Private Const EWX_FORCE As Long = 4
Private Const EWX_POWEROFF As Long = 8
'The ExitWindowsEx function either logs off, shuts down, or shuts
'down and restarts the system.
Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long
'The GetLastError function returns the calling thread's last-error
'code value. The last-error code is maintained on a per-thread basis.
'Multiple threads do not overwrite each other's last-error code.
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Const mlngWindows95 = 0
Private Const mlngWindowsNT = 1
Public glngWhichWindows32 As Long
'The GetVersion function returns the operating system in use.
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
TheLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
'The GetCurrentProcess function returns a pseudohandle for the
'current process.
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
'The OpenProcessToken function opens the access token associated with
'a process.
Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
'The LookupPrivilegeValue function retrieves the locally unique
'identifier (LUID) used on a specified system to locally represent
'the specified privilege name.
Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long
'The AdjustTokenPrivileges function enables or disables privileges
'in the specified access token. Enabling or disabling privileges
'in an access token requires TOKEN_ADJUST_PRIVILEGES access.
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 Sub SetLastError Lib "kernel32" _
(ByVal dwErrCode As Long)
Private Sub AdjustToken()
'********************************************************************
'* This procedure sets the proper privileges to allow a log off or a
'* shut down to occur under Windows NT.
'********************************************************************
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
'SetLast Error function. Do this so that the GetLastError
'function does not return a value other than zero for no
'apparent reason.
SetLastError 0
'Use the GetCurrentProcess function to set the hdlProcessHandle
'variable.
hdlProcessHandle = GetCurrentProcess()
If GetLastError <> 0 Then
MsgBox "GetCurrentProcess error==" & GetLastError
End If
OpenProcessToken hdlProcessHandle, _
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
If GetLastError <> 0 Then
MsgBox "OpenProcessToken error==" & GetLastError
End If
'Get the LUID for shutdown privilege
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
If GetLastError <> 0 Then
MsgBox "LookupPrivilegeValue error==" & GetLastError
End If
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
'Enable the shutdown privilege in the access token of this process
AdjustTokenPrivileges hdlTokenHandle, _
False, _
tkp, _
Len(tkpNewButIgnored), _
tkpNewButIgnored, _
lBufferNeeded
If GetLastError <> 0 Then
MsgBox "AdjustTokenPrivileges error==" & GetLastError
End If
End Sub
Private Sub cmdLogoff_Click()
ExitWindowsEx (EWX_LogOff), &HFFFF
MsgBox "ExitWindowsEx's GetLastError " & GetLastError
End Sub
Private Sub cmdForceLogoff_Click()
ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
MsgBox "ExitWindowsEx's GetLastError " & GetLastError
End Sub
Private Sub cmdShutdown_Click()
If glngWhichWindows32 = mlngWindowsNT Then
AdjustToken
MsgBox "Post-AdjustToken GetLastError " & GetLastError
End If
ExitWindowsEx (EWX_SHUTDOWN), &HFFFF
MsgBox "ExitWindowsEx's GetLastError " & GetLastError
End Sub
Private Sub cmdForceShutdown_Click()
If glngWhichWindows32 = mlngWindowsNT Then
AdjustToken
MsgBox "Post-AdjustToken GetLastError " & GetLastError
End If
ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE), &HFFFF
MsgBox "ExitWindowsEx's GetLastError " & GetLastError
End Sub
Private Sub Form_Load()
'********************************************************************
'* When the project starts, check the operating system used by
'* calling the GetVersion function.
'********************************************************************
Dim lngVersion As Long
lngVersion = GetVersion()
If ((lngVersion And &H80000000) = 0) Then
glngWhichWindows32 = mlngWindowsNT
MsgBox "Running Windows NT or Windows 2000"
Else
glngWhichWindows32 = mlngWindows95
MsgBox "Running Windows 95/98/Me"
End If
End Sub
3、编译成EXE,然后退出VB运行该EXE程序
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPrivate Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
i = ExitWindowsEx(EWX_FORCE, 0) ' 强迫中止没有响应的进程
Case 1
i = ExitWindowsEx(EWX_REBOOT, 0) '重新引导系统
Case 2
i = ExitWindowsEx(EWX_SHUTDOWN, 0) '关闭系统
End Select
End Sub
先建索引command按钮,应该简单吧