怎样用VB6.0编写一个关机程序?

我是VB初学者,我想请问各位大哥大姐,到底怎样才能用VB编写一个关机程序啊?尽量详细点!谢谢... 我是VB初学者,我想请问各位大哥大姐,到底怎样才能用VB编写一个关机程序啊?尽量详细点!谢谢 展开
 我来答
saddogchen
2011-03-25 · 超过27用户采纳过TA的回答
知道答主
回答量:63
采纳率:0%
帮助的人:48.8万
展开全部
我用的是XP 的系统。
VB下可以直接使用SHELL命令,详细的可以在网上找
下面的这个是关机的命令。可以加到按钮里面
Shell "shutdown -S -t 0"
度芳既7
2011-03-24
知道答主
回答量:30
采纳率:0%
帮助的人:17.8万
展开全部
'-------------关闭计算机相关------------------
' Beginning of Code
Public Const EWX_SHUTDOWN As Long = 1
Public Const EWX_FORCE As Long = 4
Public Const EWX_REBOOT = 2
Public Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Public Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Public 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 Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type

'-----------------------------------------------------

'*********************************************************************************
'**************************[ 关机程序 ] 实用于Win9x Win2000 WinXP ***************
'*********************************************************************************
'Private Type LUID
' UsedPart As Long
' IgnoredForNowHigh32BitPart As Long
'End Type
'
'Private Type TOKEN_PRIVILEGES
' PrivilegeCount As Long
' TheLuid As LUID
' Attributes As Long
'End Type
'
'' Beginning of Code
'Private Const EWX_SHUTDOWN As Long = 1
'Private Const EWX_FORCE As Long = 4
'Private Const EWX_REBOOT = 2

'Public Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
'
'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

Public Sub AdjustToken()

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

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.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

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
前台驱动
2011-03-24 · 超过16用户采纳过TA的回答
知道答主
回答量:37
采纳率:0%
帮助的人:44.1万
展开全部
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Private Sub Command1_Click()
ExitWindowsEx 1, 0
End Sub

你懂的,不解释
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2011-03-24
展开全部
染发了啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式