How to create a process in C++ on Windows?

c++, process, visual-c++, winapi

Solution

`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.

Problem

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.

Original source

Related problems