一、CreateProcess
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName, //可执行文件的文件名
_Inout_opt_ LPTSTR lpCommandLine, //命令行字符串,长度最大可以达到32768个字符
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, //进程的安全描述符
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, //主线程内核对象的的安全描述符
_In_ BOOL bInheritHandles, //进程和线程句柄可不可以继承
_In_ DWORD dwCreationFlags, //创建标志,(1)如何创建进程(2)进程的优先级,参见MSDN
_In_opt_ LPVOID lpEnvironment, //指向环境变量的内存块指针
_In_opt_ LPCTSTR lpCurrentDirectory, //指向当前目录项
_In_ LPSTARTUPINFO lpStartupInfo, //启动信息
_Out_ LPPROCESS_INFORMATION lpProcessInformation //指向一个PROCESS_INFORMATION结构的指针
);
一个创建进程的实例:
#include<windows.h>
#include<tchar.h>
int _tmain()
{
STARTUPINFO info;
ZeroMemory(&info, sizeof(info));
info.cb = sizeof(info);
PROCESS_INFORMATION si;
if (!CreateProcess(L"H:\\win32\\GetVesion\\Debug\\GetVesion.exe", NULL, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, NULL, NULL, &info, &si))
{
_tprintf(L"CreateProcess Failed=%d!\n",GetLastError());
_gettchar();
return 0;
}
CloseHandle(si.hProcess); //关掉句柄,但是不关闭进程,同理可以关闭线程句柄
OpenProcess(NULL,FALSE,si.dwProcessId);//如果关掉后想重新获得,则用OpenProcess
_gettchar();
return 0;
}
还是把MSDN上面关于CreateProcess的 dwCreationFlags 的文档粘贴在上面吧
Process Creation Flags
The following process creation flags are used by the CreateProcess, CreateProcessAsUser, CreateProcessWithLogonW, andCreateProcessWithTokenW functions. They can be specified in any combination, except as noted.