导致“无响应”的长shell命令显示 [英] Long shell command causing "Not Responding" to show
本文介绍了导致“无响应”的长shell命令显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不得不使用shell在VB6应用程序中安装一些支持文件。我正在使用下面的代码,因此请发送安装命令。有没有办法通过使用 WaitForSingleObject
以外的东西集成到 Doevents
中,这样应用程序就会响应,至少不会显示没有回复?
谢谢
公开 功能 ShellSync(_
ByVal PathName 作为 字符串,_
ByVal WindowStyle 作为 VbAppWinStyle)作为 长
' Shell并等待。返回退出代码结果,在任何错误上引发
例外。
Dim lngPid 作为 长
Dim lngHandle 作为 长
Dim lngExitCode 作为 长
lngPid = Shell(PathName,WindowStyle)
如果 lngPid<> 0 然后
lngHandle = OpenProcess(SYNCHRONIZE _
或 PROCESS_QUERY_INFORMATION, 0 ,lngPid)
如果 lngHandle< ;> 0 然后
WaitForSingleObject lngHandle,INFINITE
如果 GetExitCodeProcess(lngHandle,lngExitCode)<> 0 然后
ShellSync = lngExitCode
CloseHandle lngHandle
Else
CloseHandle lngHandle
Err.Raise& H8004AA00, ShellSync,_
无法检索退出代码,错误 _
& CStr (Err.LastDllError)
结束 如果
其他
Err.Raise& H8004AA01, < span class =code-string> ShellSync,_
无法打开子项流程
结束 如果
Else
Err.Raise& H8004AA02, ShellSync,_
Shell子进程失败
结束 如果
结束 功能跨度>
解决方案
您可以使用WshShell.Run。如果您等待子进程,它不会冻结。
WshShell .RUN
I am having to install some support files from within a VB6 application by using a shell. I am using the code below so send the command for the install. Is there a way to integrate in Doevents
by using something other than WaitForSingleObject
so the application would be responsive, at least not showing "Not Responding"?
Thanks
Public Function ShellSync( _
ByVal PathName As String, _
ByVal WindowStyle As VbAppWinStyle) As Long
'Shell and wait. Return exit code result, raise an
'exception on any error.
Dim lngPid As Long
Dim lngHandle As Long
Dim lngExitCode As Long
lngPid = Shell(PathName, WindowStyle)
If lngPid <> 0 Then
lngHandle = OpenProcess(SYNCHRONIZE _
Or PROCESS_QUERY_INFORMATION, 0, lngPid)
If lngHandle <> 0 Then
WaitForSingleObject lngHandle, INFINITE
If GetExitCodeProcess(lngHandle, lngExitCode) <> 0 Then
ShellSync = lngExitCode
CloseHandle lngHandle
Else
CloseHandle lngHandle
Err.Raise &H8004AA00, "ShellSync", _
"Failed to retrieve exit code, error " _
& CStr(Err.LastDllError)
End If
Else
Err.Raise &H8004AA01, "ShellSync", _
"Failed to open child process"
End If
Else
Err.Raise &H8004AA02, "ShellSync", _
"Failed to Shell child process"
End If
End Function
解决方案
You can use WshShell.Run. It is not freeze if you wait the child process.
WshShell.Run
这篇关于导致“无响应”的长shell命令显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文