我的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可以实现关机
展开
 我来答
paopaodan54
2009-11-05 · TA获得超过214个赞
知道答主
回答量:167
采纳率:0%
帮助的人:0
展开全部
我的习惯是用shell里的shutdown这个命令
a=shell("shutdown -f -s -t 0")
关系
Winnip888
2009-11-05 · TA获得超过1996个赞
知道小有建树答主
回答量:676
采纳率:0%
帮助的人:562万
展开全部
EWX_LOGOFF
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
mosesmoses0651
2009-11-05 · TA获得超过2718个赞
知道小有建树答主
回答量:824
采纳率:0%
帮助的人:650万
展开全部
这个不行,试下这个吧,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 好了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式