如何在Windows上使用C ++创建进程? [英] How to create a process in C++ on Windows?

查看:787
本文介绍了如何在Windows上使用C ++创建进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何在VC ++中创建一个进程?我需要执行

  regasm.exe testdll /tlb:test.tlb / codebase 

解决方案

code> regasm.exe (装配注册工具)更改Windows注册表,因此,如果您要启动 regasm.exe 您可以使用以下代码升级过程:

  #includestdafx.h
#includewindows.h
#includeshellapi.h

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

shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = Lrunas;
shExecInfo.lpFile = Lregasm.exe;
shExecInfo.lpParameters = Ltestdll /tlb:test.tlb / codebase;
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_NORMAL;
shExecInfo.hInstApp = NULL;

ShellExecuteEx(&shExecInfo);

return 0;
}

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


Can anyone tell me how to create a process in VC++? I need to execute

regasm.exe testdll /tlb:test.tlb /codebase

command in that process.

解决方案

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" 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 ++创建进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆