windows核心编程-CreateProcess创建进程
来源:互联网 发布:手机淘宝买家实名认证 编辑:程序博客网 时间:2024/05/19 00:55
一、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.
- 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 effect. If the calling process is associated with a job, the job must set the JOB_OBJECT_LIMIT_BREAKAWAY_OK limit.
- CREATE_DEFAULT_ERROR_MODE
- 0x04000000
The new process does not inherit the error mode of the calling process. Instead, the new process gets the default error mode.
This feature is particularly useful for multithreaded shell applications that run with hard errors disabled.
The default behavior is for the new process to inherit the error mode of the caller. Setting this flag changes that default behavior.
- CREATE_NEW_CONSOLE
- 0x00000010
The new process has a new console, instead of inheriting its parent's console (the default). For more information, seeCreation of a Console.
This flag cannot be used with DETACHED_PROCESS.
- CREATE_NEW_PROCESS_GROUP
- 0x00000200
The new process is the root process of a new process group. The process group includes all processes that are descendants of this root process. The process identifier of the new process group is the same as the process identifier, which is returned in the lpProcessInformation parameter. Process groups are used by the GenerateConsoleCtrlEvent function to enable sending a CTRL+BREAK signal to a group of console processes.
If this flag is specified, CTRL+C signals will be disabled for all processes within the new process group.
This flag is ignored if specified with CREATE_NEW_CONSOLE.
- CREATE_NO_WINDOW
- 0x08000000
The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.
This flag is ignored if the application is not a console application, or if it is used with either CREATE_NEW_CONSOLE orDETACHED_PROCESS.
- CREATE_PROTECTED_PROCESS
- 0x00040000
The process is to be run as a protected process. The system restricts access to protected processes and the threads of protected processes. For more information on how processes can interact with protected processes, see Process Security and Access Rights.
To activate a protected process, the binary must have a special signature. This signature is provided by Microsoft but not currently available for non-Microsoft binaries. There are currently four protected processes: media foundation, audio engine, Windows error reporting, and system. Components that load into these binaries must also be signed. Multimedia companies can leverage the first two protected processes. For more information, see Overview of the Protected Media Path.
Windows Server 2003 and Windows XP: This value is not supported.
- CREATE_PRESERVE_CODE_AUTHZ_LEVEL
- 0x02000000
Allows the caller to execute a child process that bypasses the process restrictions that would normally be applied automatically to the process.
- CREATE_SEPARATE_WOW_VDM
- 0x00000800
This flag is valid only when starting a 16-bit Windows-based application. If set, the new process runs in a private Virtual DOS Machine (VDM). By default, all 16-bit Windows-based applications run as threads in a single, shared VDM. The advantage of running separately is that a crash only terminates the single VDM; any other programs running in distinct VDMs continue to function normally. Also, 16-bit Windows-based applications that are run in separate VDMs have separate input queues. That means that if one application stops responding momentarily, applications in separate VDMs continue to receive input. The disadvantage of running separately is that it takes significantly more memory to do so. You should use this flag only if the user requests that 16-bit applications should run in their own VDM.
- CREATE_SHARED_WOW_VDM
- 0x00001000
The flag is valid only when starting a 16-bit Windows-based application. If the DefaultSeparateVDM switch in the Windows section of WIN.INI is TRUE, this flag overrides the switch. The new process is run in the shared Virtual DOS Machine.
- CREATE_SUSPENDED
- 0x00000004
The primary thread of the new process is created in a suspended state, and does not run until the ResumeThread function is called.
- CREATE_UNICODE_ENVIRONMENT
- 0x00000400
If this flag is set, the environment block pointed to by lpEnvironment uses Unicode characters. Otherwise, the environment block uses ANSI characters.
- DEBUG_ONLY_THIS_PROCESS
- 0x00000002
The calling thread starts and debugs the new process. It can receive all related debug events using the WaitForDebugEventfunction.
- DEBUG_PROCESS
- 0x00000001
The calling thread starts and debugs the new process and all child processes created by the new process. It can receive all related debug events using the WaitForDebugEvent function.
A process that uses DEBUG_PROCESS becomes the root of a debugging chain. This continues until another process in the chain is created with DEBUG_PROCESS.
If this flag is combined with DEBUG_ONLY_THIS_PROCESS, the caller debugs only the new process, not any child processes.
- DETACHED_PROCESS
- 0x00000008
For console processes, the new process does not inherit its parent's console (the default). The new process can call theAllocConsole function at a later time to create a console. For more information, see Creation of a Console.
This value cannot be used with CREATE_NEW_CONSOLE.
- EXTENDED_STARTUPINFO_PRESENT
- 0x00080000
The process is created with extended startup information; the lpStartupInfo parameter specifies a STARTUPINFOEXstructure.
Windows Server 2003 and Windows XP: This value is not supported.
- INHERIT_PARENT_AFFINITY
- 0x00010000
The process inherits its parent's affinity. If the parent process has threads in more than one processor group, the new process inherits the group-relative affinity of an arbitrary group in use by the parent.
Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This value is not supported.
- 创建进程CreateProcess函数----windows 核心编程
- windows核心编程-CreateProcess创建进程
- 创建进程CreateProcess函数---------《windows核心编程》读书笔记(3)
- 重读Windows核心编程--CreateProcess
- windows核心编程-CreateProcess详解
- Windows核心编程 进程--CreateProcess函数 终止进程和子进程 进程的权限
- Windows创建进程winAPI-CreateProcess
- Windows下创建进程-CreateProcess()
- Windows CreateProcess fail 创建进程失败。
- windows核心编程--进程
- windows核心编程--进程
- Windows核心编程:进程
- windows 核心编程(进程)
- 《Windows核心编程》进程
- Windows核心编程 - 进程
- windows核心编程-进程
- windows核心编程---进程
- 【Windows 核心编程】Windows 核心编程 -- 进程
- swagger实用接口文档生成框架
- 关于跨域通信问题及解决方案
- 高性能网络编程7--tcp连接的内存使用
- MySQL 导入、导出备份 mysqldump工具用法
- 微信公众号开发前期基本配置-ngrok映射
- windows核心编程-CreateProcess创建进程
- ffmpeg学习一:启动篇(学习计划与环境搭建)
- opencv31联通阈分析
- hdu2087剪花布条
- 新人零基础学习HTML5五步走
- 色阶变换做的一个颜色渐变效果
- 把自己的可执行文件push到adb下system/bin/下
- 百度url 参数详解全
- Active Directory的脱机碎片整理,Active Directory系列之七