vb用createprocess启动其他应用程序

博客展示了一段VBA代码,定义了PROCESS_INFORMATION、STARTUPINFO、SECURITY_ATTRIBUTES等类型,声明了CreateProcess、WaitForSingleObject、Sleep等函数。在Command1_Click事件中,使用CreateProcess启动360zip.exe程序,并通过WaitForSingleObject等待程序结束,结束后弹出提示框。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Option Explicit

 

Private Type PROCESS_INFORMATION

        hProcess As Long

        hThread As Long

        dwProcessId As Long

        dwThreadId As Long

End Type

 

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 SECURITY_ATTRIBUTES

        nLength As Long

        lpSecurityDescriptor As Long

        bInheritHandle As Long

End Type

 

Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _

  ByVal lpApplicationName As String, _

  ByVal lpCommandLine As String, _

  lpProcessAttributes As SECURITY_ATTRIBUTES, _

  lpThreadAttributes As SECURITY_ATTRIBUTES, _

  ByVal bInheritHandles As Long, _

  ByVal dwCreationFlags As Long, _

  lpEnvironment As Any, _

  ByVal lpCurrentDriectory As String, _

  lpStartupInfo As STARTUPINFO, _

  lpProcessInformation As PROCESS_INFORMATION) 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 Sub Command1_Click()

  Dim sInfo As STARTUPINFO

  Dim psInfo As PROCESS_INFORMATION

  Dim pAttr As SECURITY_ATTRIBUTES

  Dim tAttr As SECURITY_ATTRIBUTES

  Dim nRet As Long

  Dim nElapse As Integer

 

  nRet = CreateProcess("C:\Program Files (x86)\360\360zip\360zip.exe", "", pAttr, tAttr, 0, 0, 0, "c:\", sInfo, psInfo)

  If nRet = 0 Then Exit Sub

  nElapse = 0

  While 1 > 0

    nRet = WaitForSingleObject(psInfo.hProcess, 1000)

    If nRet = 0 Then

      MsgBox "Done!"

      Exit Sub

    End If

   

    Label1.Caption = CStr(nElapse)

    nElapse = nElapse + 1

    Sleep (1000)

    DoEvents

  Wend

 

 

End Sub

 

摘自 JOEL.LEE的专栏

转载于:https://www.cnblogs.com/wgscd/p/9557846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值