windows核心编程-CreateProcess创建进程

本文深入探讨了在Windows环境中如何利用CreateProcess函数创建进程,并详细解析了Process Creation Flags的各种组合及其用途。
摘要由CSDN通过智能技术生成

一、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 CreateProcessCreateProcessAsUserCreateProcessWithLogonW, andCreateProcessWithTokenW functions. They can be specified in any combination, except as noted.

Constant/value Description
CREATE_BREAKAWAY_FROM_JOB 0x01000000

The child processes of a process associated with a job are not associated with the job.

If the calling process is not associated with a job, this constant has no

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值