How to create a process in C++ on Windows?(如何在 Windows 上用 C++ 创建进程?)
问题描述
谁能告诉我如何在 VC++ 中创建一个进程?我需要执行
Can anyone tell me how to create a process in VC++? I need to execute
regasm.exe testdll /tlb:test.tlb /codebase
该过程中的命令.
推荐答案
regasm.exe(程序集注册工具)对 Windows 注册表进行更改,因此如果您想启动 regasm.exe 作为提升的进程,您可以使用以下代码:
regasm.exe(Assembly Registration Tool) makes changes to the Windows Registry, so if you want to start regasm.exe as elevated process you could use the following code:
#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 注册表的某些部分需要管理员权限.
shExecInfo.lpVerb = L"runas" means that process will be started with elevated privileges. If you don't want that just set shExecInfo.lpVerb to NULL. But under Vista or Windows 7 it's required administrator rights to change some parts of Windows Registry.
这篇关于如何在 Windows 上用 C++ 创建进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Windows 上用 C++ 创建进程?
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
