请教各位,如何在程序中远程启动和关闭一个程序?使其在程序本地处于运行状态或关闭状态。各位大虾帮帮忙,谢谢!

解决方案 »

  1.   

    启动程序:
    CreateProcess
    The CreateProcess function creates a new process and its primary thread. The new process runs the specified executable file. To create a process that runs in a different security context, use the CreateProcessAsUser or CreateProcessWithLogonW function. BOOL CreateProcess(
      LPCTSTR lpApplicationName,                 // name of executable module
      LPTSTR lpCommandLine,                      // command line string
      LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
      LPSECURITY_ATTRIBUTES lpThreadAttributes,  // SD
      BOOL bInheritHandles,                      // handle inheritance option
      DWORD dwCreationFlags,                     // creation flags
      LPVOID lpEnvironment,                      // new environment block
      LPCTSTR lpCurrentDirectory,                // current directory name
      LPSTARTUPINFO lpStartupInfo,               // startup information
      LPPROCESS_INFORMATION lpProcessInformation // process information
    );关闭程序:
    ...
    SendMessage(hWnd,WM_CLOSE);
    ...
      

  2.   

    使用WMI:
    Process.Create( _
      CommandLine As String, _
      CurrentDirectory As String, _
      ProcessStartupInformation As Win32_ProcessStartup, _
      ByRef ProcessId As Integer _
    ) As Integer
      

  3.   

    关闭进程时也可以用 WaitForSingleObject 来等待被启动进程结束,这样就可以在被启动进程完成后在作相关操作了。