设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4108|回复: 3
打印 上一主题 下一主题

等待shell结束再运行后面代码

[复制链接]

8

主题

3

好友

169

积分

版主

Rank: 7Rank: 7Rank: 7

生肖
星座
摩羯座
性别
保密
跳转到指定楼层
楼主
发表于 2013-10-5 23:45:29 |只看该作者 |倒序浏览
本帖最后由 sky_yx 于 2015-12-30 14:19 编辑

'模块
  Option Explicit
   
  Type STARTUPINFO
  cb As Long
  lpReserved As String
  lpDesktop As String
  lpTitle As String
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
  End Type
  Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadID As Long
  End Type
  Global Const NORMAL_PRIORITY_CLASS = &H20&
  Global Const INFINITE = -1&
  Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean
  Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  Declare Function CreateProcessA Lib "kernel32" ( _
  ByVal lpApplicationName As Long, _
  ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal _
  lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal _
  dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal _
  lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, _
  lpProcessInformation As PROCESS_INFORMATION) As Long
   
  Public Sub ShellAndWait(cmdline$)
  Dim NameOfProc As PROCESS_INFORMATION
  Dim NameStart As STARTUPINFO
  Dim X As Long
   
  NameStart.cb = Len(NameStart)
  X = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, _
  0&, 0&, NameStart, NameOfProc)
  X = WaitForSingleObject(NameOfProc.hProcess, INFINITE)
  X = CloseHandle(NameOfProc.hProcess)
  End Sub
'窗口
Private Declare Function dcWaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
    dcWaitForSingleObject OpenProcess(SYNCHRONIZE, 0, Shell("cmd.exe", vbNormalFocus)), 10000 '后面的10000 是超时时间
    MsgBox "CMD.EXE已结束"
End Sub

分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
分享淘帖0 收藏收藏0 评分评分

8

主题

3

好友

169

积分

版主

Rank: 7Rank: 7Rank: 7

生肖
星座
摩羯座
性别
保密
沙发
发表于 2013-10-5 23:45:38 |只看该作者
本帖最后由 sky_yx 于 2015-12-30 14:19 编辑

-------
[vgtve]
谢谢啦,辛苦啦。感谢感谢!
情侣皮肤一左一右 心情签名 qq网名大全 qq带字情侣头像 小清新图片 
[buynian2]
好帖要顶,楼主的头像还是不错滴-

回复

使用道具 评分 举报

8

主题

3

好友

169

积分

版主

Rank: 7Rank: 7Rank: 7

生肖
星座
摩羯座
性别
保密
板凳
发表于 2013-10-5 23:45:46 |只看该作者
本帖最后由 sky_yx 于 2015-12-30 14:19 编辑

------
[buynian2]
好帖要顶,楼主的头像还是不错滴-------
[buynian2]
好帖要顶,楼主的头像还是不错滴

回复

使用道具 评分 举报

8

主题

3

好友

169

积分

版主

Rank: 7Rank: 7Rank: 7

生肖
星座
摩羯座
性别
保密
地板
发表于 2013-10-5 23:45:57 |只看该作者
本帖最后由 sky_yx 于 2015-12-30 14:19 编辑

-------

回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 立即注册


手机版|SKY外语计算机学习 ( 粤ICP备12031577 )    

GMT+8, 2024-12-22 19:54 , Processed in 0.104164 second(s), 25 queries .

回顶部