vb运行批处理文件
各位朋友,我有调用.bat文件时遇到了一些对我来说剌手的问题。就是.bat文件还没有运行完,vb的其它程序就开始运行了,请各位告诉我应该怎么样避免这个问题。本人非常感谢。...
各位朋友,我有调用.bat文件时遇到了一些对我来说剌手的问题。就是.bat文件还没有运行完,vb的其它程序就开始运行了,请各位告诉我应该怎么样避免这个问题。本人非常感谢。
展开
3个回答
展开全部
VB是异步运行模式,需要用API达到同步运行的效果,这个已经在百度发过贴了,自己要多搜搜,给你个函数
'在标准模块中写入下列代码
Public Const SYNCHRONIZE = &H100000
Public Const INFINITE = &HFFFFFFFF
Public Const WAIT_TIMEOUT = &H102&
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
sub RunProgram(FileName as string)'参数为文件名
Dim pId As Long, pHnd As Long, ret
pId = Shell(FileName, vbNormalFocus)
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Do
ret = WaitForSingleObject(pHnd, 0)
DoEvents
Loop While ret = WAIT_TIMEOUT
CloseHandle pHnd
End If
End Sub
然后在主窗体中就不要用Shell了,只需要用RunProgram 你的程序名
'在标准模块中写入下列代码
Public Const SYNCHRONIZE = &H100000
Public Const INFINITE = &HFFFFFFFF
Public Const WAIT_TIMEOUT = &H102&
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
sub RunProgram(FileName as string)'参数为文件名
Dim pId As Long, pHnd As Long, ret
pId = Shell(FileName, vbNormalFocus)
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Do
ret = WaitForSingleObject(pHnd, 0)
DoEvents
Loop While ret = WAIT_TIMEOUT
CloseHandle pHnd
End If
End Sub
然后在主窗体中就不要用Shell了,只需要用RunProgram 你的程序名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
pid = Shell("C:\haha.bat", vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
ExitEvent = WaitForSingleObject(hProcess, INFINITE)
Call CloseHandle(hProcess)
这些函数都到api查看器里找,都是标准api
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
ExitEvent = WaitForSingleObject(hProcess, INFINITE)
Call CloseHandle(hProcess)
这些函数都到api查看器里找,都是标准api
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
额~~你是要转换成VB代码?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询