VB中如何调用dos命令。

比如我现在要做一个恶搞关机的程序,在dos中是:shutdown-s如何在VB中调用它,注意不比显示dos窗口最好。如果不调用dos,直接实现关机命令也可。直接写代码,带... 比如我现在要做一个恶搞关机的程序,在dos中 是:shutdown -s 如何在VB中调用它,注意不比显示dos窗口最好。如果不调用dos,直接实现关机命令也可。直接写代码,带一点解释最好,我给15分,如果能够解决问题,我在追加15分,说还算数。为的是防止此题没人答,白白浪费财富。 展开
 我来答
良水毅魔滴奋p
2010-12-13 · TA获得超过115个赞
知道答主
回答量:61
采纳率:0%
帮助的人:0
展开全部
'四个CommandBox控件,分别为:重新启动计算机、关闭计算机、注销计算机、退出。纯VB

Option Explicit
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
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
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
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const HELP_CONTENTS = &H3&
Const EWX_WAIT = 16
Const EWX_REBOOT = 2 '重起
Const EWX_LOGOFF = 0 '注销
Const EWX_FORCE = 4 '终止没有响应的进程
Const EWX_SHUTDOWN = 8 '关闭电源

Private Sub Command1_Click()
'重新启动计算机
ExitWindowsEx EWX_REBOOT, 0
End Sub

Private Sub Command2_Click()
'关闭计算机
ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Command4_Click()
ExitWindowsEx EWX_LOGOFF, 0
End Sub
Private Sub Form_Load()
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()
OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED
lBufferNeeded = 0
'允许当前应用程序有关闭操作系统的权限
AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded
End Sub
yang_zi2009
2010-12-13 · TA获得超过469个赞
知道小有建树答主
回答量:612
采纳率:100%
帮助的人:673万
展开全部
private command1_click()
shell "shutdown -s -t 0 -f",vbHide
end sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
loumou
2010-12-13 · TA获得超过865个赞
知道小有建树答主
回答量:1049
采纳率:0%
帮助的人:727万
展开全部
vb 中
shell "shutdown -s",vbhide
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式