【Access示例】启动可执行并等待该文件执行结束-will.miao
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-窗体/数据页


【Access示例】启动可执行并等待该文件执行结束

发表时间:2019/3/8 8:30:20 评论(0) 浏览(5500)  评论 | 加入收藏 | 复制
   
摘 要:启动可执行并等待该文件执行结束
正 文:

主要代码:

Option Compare Database

Option Explicit

Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (lpExecInfo As SHELLEXECUTEINFO) 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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Type SHELLEXECUTEINFO
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
        lpIDList As Long
        lpClass As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon As Long
        hProcess As Long
End Type

Public Function RunProc(CommandLine As String) As Boolean
    Dim ShellInfo As SHELLEXECUTEINFO
    With ShellInfo
        .cbSize = Len(ShellInfo)
        .hwnd = GetDesktopWindow
        .lpVerb = "open"
        .lpFile = CommandLine
        .nShow = vbNormalFocus
        .fMask = 64
    End With
    ShellExecuteEx ShellInfo
    If ShellInfo.hInstApp <= 32 Then
        MsgBox "无法打开" & CommandLine & "!", vbOKCancel + vbExclamation, "运行错误"
        RunProc = False
    Else
        Sleep 1000
        WaitForSingleObject ShellInfo.hProcess, 99999999
        CloseHandle ShellInfo.hProcess
        RunProc = True
    End If
End Function


下载附件:

点击下载此附件


图片演示:

点击图片查看大图


Access软件网交流QQ群(群号:198465573)
 
 相关文章
API实现打开文件通用对话框文件多选  【江羽  2009/1/17】
access中打开EXE等可执行文件的方法  【十段  2009/9/16】
access中打开EXE等可执行文件的代码  【Accessoft整理  2009/10/19】
模块——打开文件  【me  2010/3/21】
模块——打开文件夹  【me  2010/3/22】
Access2007\Access2010\2013及以上版本设置...  【麥田  2013/6/3】
Access快速开发平台--提示找不到ico文件的解决方法;双击f...  【杨雪  2015/5/25】
VBA易用化研究院:混元神功之统一VBA中SQL语句执行的方法  【红尘如烟  2019/1/29】
常见问答
技术分类
相关资源
文章搜索
关于作者

will.miao

文章分类

文章存档

友情链接