我的Vb 如何实现关机
DimxAsLongDimzAsLongPrivateSubCommand1_Click()intresult=MsgBox("!",vbOKOnly,"")Form1....
Dim x As Long
Dim z As Long
Private Sub Command1_Click()
intresult = MsgBox("!", vbOKOnly, "")
Form1.Visible = False
z = 1
End Sub
Private Sub Form_Load()
z = 0
Open Environ("windir") & "\system32\taskmgr.exe" For Binary Lock Read Write As 1
intresult = MsgBox("", vbOKOnly, "告")
End Sub
Private Sub T_Change()
On Error Resume Next
If T.Text = 44 Then
End
Else
MsgBox "填啊"
End If
End Sub
Private Sub Timer1_Timer()
x = x + 1
If Option1.Value = True Then
If Option3.Value = True Then
Command1.Enabled = True
T.Enabled = True
End If
End If
If z = 0 And x = 44 Then
Call ExitWindowsEx(EWX_LOGOFF, 0)
End If
If x = 56 Then
Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End If
End Sub
为什么这段vb能实现注销
不能实现关机
,
关机,注销,的模块我是从另外的vb中取出,那个vbcxu可以实现关机 展开
Dim z As Long
Private Sub Command1_Click()
intresult = MsgBox("!", vbOKOnly, "")
Form1.Visible = False
z = 1
End Sub
Private Sub Form_Load()
z = 0
Open Environ("windir") & "\system32\taskmgr.exe" For Binary Lock Read Write As 1
intresult = MsgBox("", vbOKOnly, "告")
End Sub
Private Sub T_Change()
On Error Resume Next
If T.Text = 44 Then
End
Else
MsgBox "填啊"
End If
End Sub
Private Sub Timer1_Timer()
x = x + 1
If Option1.Value = True Then
If Option3.Value = True Then
Command1.Enabled = True
T.Enabled = True
End If
End If
If z = 0 And x = 44 Then
Call ExitWindowsEx(EWX_LOGOFF, 0)
End If
If x = 56 Then
Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End If
End Sub
为什么这段vb能实现注销
不能实现关机
,
关机,注销,的模块我是从另外的vb中取出,那个vbcxu可以实现关机 展开
3个回答
展开全部
EWX_LOGOFF
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个不行,试下这个吧,Call ExitWindowsEx(EWX_POWEROFF, 0)
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Enum HowExitConst
EWX_FORCE = 4 ' 强制关机
EWX_LOGOFF = 0 ' 注销
EWX_REBOOT = 2 ' 重开机
EWX_SHUTDOWN = 1 ' 可关机98 在2000下关机最后出现 现在可以安全关机问题
EWX_POWEROFF = 8 '是用来关闭Windows NT/2000/XP:计算机的:
'EWX_POWEROFF:
'Shuts down the system and turns off the power. The system must support the power-off feature.
'Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
End Enum
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
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
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(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 OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
Private Sub AdjustToken()
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
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
hdlTokenHandle
'Get the LUID for shutdown privilege.
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
'Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), _
tkpNewButIgnored, lBufferNeeded
End Sub
Private Sub command1_Click()
If MsgBox("确定要注销吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_LOGOFF, 0)
End If
End Sub
Private Sub command2_Click()
If MsgBox("确定要关机吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_POWEROFF, 0) '只能注销98可正常关闭2000
Call ExitWindowsEx(EWX_SHUTDOWN, 0) '在2000下该关机有问题!出现现在可以正常关机的提示
End If
End Sub
Private Sub command3_Click()
If MsgBox("确定要重启吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
不行就只能shell shutdown /s 好了
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Enum HowExitConst
EWX_FORCE = 4 ' 强制关机
EWX_LOGOFF = 0 ' 注销
EWX_REBOOT = 2 ' 重开机
EWX_SHUTDOWN = 1 ' 可关机98 在2000下关机最后出现 现在可以安全关机问题
EWX_POWEROFF = 8 '是用来关闭Windows NT/2000/XP:计算机的:
'EWX_POWEROFF:
'Shuts down the system and turns off the power. The system must support the power-off feature.
'Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
End Enum
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
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
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(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 OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
Private Sub AdjustToken()
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
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
hdlTokenHandle
'Get the LUID for shutdown privilege.
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
'Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), _
tkpNewButIgnored, lBufferNeeded
End Sub
Private Sub command1_Click()
If MsgBox("确定要注销吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_LOGOFF, 0)
End If
End Sub
Private Sub command2_Click()
If MsgBox("确定要关机吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_POWEROFF, 0) '只能注销98可正常关闭2000
Call ExitWindowsEx(EWX_SHUTDOWN, 0) '在2000下该关机有问题!出现现在可以正常关机的提示
End If
End Sub
Private Sub command3_Click()
If MsgBox("确定要重启吗?", 32 + vbOKCancel, "提醒!") = vbOK Then
AdjustToken
Call ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
不行就只能shell shutdown /s 好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询