vb|解决|源代码|执行|shell|异步|同步
阿里西西web开发团队在开发一个asp系统,需要同步调用vb(dll)执行的shell操作,asp->vb(dll)->shell->rar.exe同步执行exe文件。
由于shell是异步处理,这个问题让我们头疼了很久,最终还是通过百度找到了几个不错的函数,调试过,效果还不错,建议可以先用vb建exe来调试好了,再放入DLL编译给ASP调用。
代码如下:
以下是用vb制作一个exe文件进行调试,打开记事本和计算器示例: Private 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 Private Type PROCESS_INFORMATION Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _ Private Declare Function CreateProcessA Lib "kernel32" (ByVal _ Private Declare Function CloseHandle Lib "kernel32" _ Private Declare Function GetExitCodeProcess Lib "kernel32" _ Private Const NORMAL_PRIORITY_CLASS = &H20& Public Function ExecCmd(cmdline$) ’ Initialize the STARTUPINFO structure: ’ Start the shelled application: ’ Wait for the shelled application to finish: Sub Form_Click() End Sub |
方法二:
以下是引用片段: Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Const SYNCHRONIZE = &H100000 Public Function ShellForWait(sAppName As String, Optional ByVal lShowWindow As VbAppWinStyle = vbMinimizedFocus, Optional ByVal lWaitTime As Long = 0) As Boolean ShellForWait("notepad.exe",,&HFFFF) |
方法三:
以下是引用片段: 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 Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Const INFINITE = &HFFFFFFFF Private Sub cmdOpen_Click() Private Sub OpenFileWait(tkShellFile As String, tkFileName As String) |
如果你觉得不错,阿里西西(Alixixi.com)网站还有更多精彩资源,不要错过,记住我们的网址!