如何在Windows上用C++创建进程?

Cut*_*ute 5 c++ winapi process visual-c++

谁能告诉我如何在VC++中创建一个进程?我需要执行

regasm.exe testdll /tlb:test.tlb /codebase
Run Code Online (Sandbox Code Playgroud)

该过程中的命令.

Kir*_*sky 10

regasm.exe(程序集注册工具)对Windows注册表进行更改,因此如果要以regasm.exe提升的进程启动,可以使用以下代码:

#include "stdafx.h"
#include "windows.h"
#include "shellapi.h"

int _tmain(int argc, _TCHAR* argv[])
{
      SHELLEXECUTEINFO shExecInfo;

      shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

      shExecInfo.fMask = NULL;
      shExecInfo.hwnd = NULL;
      shExecInfo.lpVerb = L"runas";
      shExecInfo.lpFile = L"regasm.exe";
      shExecInfo.lpParameters = L"testdll /tlb:test.tlb /codebase";
      shExecInfo.lpDirectory = NULL;
      shExecInfo.nShow = SW_NORMAL;
      shExecInfo.hInstApp = NULL;

      ShellExecuteEx(&shExecInfo);

      return 0;
}
Run Code Online (Sandbox Code Playgroud)

shExecInfo.lpVerb = L"runas"表示将使用提升的权限启动进程.如果你不想那只是设置shExecInfo.lpVerb为NULL.但在Vista或Windows 7下,需要管理员权限才能更改Windows注册表的某些部分.


ral*_*nja 4

您需要阅读msdn 中的CreateProcess() 。该页面上有示例代码。