[英]How to create a process in C++ on Windows?
谁能告诉我如何在VC ++中创建一个进程? 我需要执行
regasm.exe testdll /tlb:test.tlb /codebase
该过程中的命令。
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;
}
shExecInfo.lpVerb = L"runas"
表示将使用提升的权限启动进程。 如果你不想那只是将shExecInfo.lpVerb
设置为NULL。 但在Vista或Windows 7下,需要管理员权限才能更改Windows注册表的某些部分。
您需要阅读msdn中的CreateProcess() 。 该页面上有示例代码。
使用CreateProcess()生成进程,检查返回值以确保它开始正常,然后关闭进程和线程的句柄或使用WaitForSingleObject()等待它完成然后关闭句柄。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.