vb用createprocess启动其他应用程序

Posted wgscd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb用createprocess启动其他应用程序相关的知识,希望对你有一定的参考价值。

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)360360zip360zip.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的专栏

以上是关于vb用createprocess启动其他应用程序的主要内容,如果未能解决你的问题,请参考以下文章

使用 CreateProcess 从 Win32 C++ 应用程序启动 Java 应用程序时出错

使用 CreateProcess 启动子程序时,不会在父程序的工作目录中搜索 DLL

在 Windows CE 中使用 CreateProcess 启动的应用程序不会作为应用程序显示在任务管理器中

vb如何控制其他程序?

Windows 7 CreateProcess,子进程无法写入文件?

CreateProcess() 无法正常工作