#include
BOOL CreateProcess
(
LPCTSTRlpApplicationName,
LPTSTRlpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes。
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
详见百度百科
#include
BOOL CreateProcess
(
LPCTSTRlpApplicationName,
LPTSTRlpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes。
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
#include
#include
int main(int argc, char *argv[])
{
char szCommandLine[] = "notepad";
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW; // 指定wShowWindow成员有效
si.wShowWindow = TRUE; // 此成员设为TRUE的话则显示新建进程的主窗口
BOOL bRet = CreateProcess (
NULL, // 不在此指定可执行文件的文件名
szCommandLine, // 命令行参数
NULL, // 默认进程安全性
NULL, // 默认进程安全性
FALSE, // 指定当前进程内句柄不可以被子进程继承
CREATE_NEW_CONSOLE, // 为新进程创建一个新的控制台窗口
NULL, // 使用本进程的环境变量
NULL, // 使用本进程的驱动器和目录
&si,
&pi) ;
if(bRet)
{
// 不使用的句柄最好关掉
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
printf("新进程的ID号:%d\n",pi.dwProcessId);
printf("新进程的主线程ID号:%d\n",pi.dwThreadId);
}
return 0;
}
这是百度百科的例子,看一下具体的参数说明就明白了!
查MSDN啊,我查到的如下:
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
RequirementsClientRequires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.ServerRequires Windows Server 2003, Windows 2000 Server, or Windows NT Server.HeaderDeclared in Winbase.h; include Windows.h.
Library
Link to Kernel32.lib.
DLLRequires Kernel32.dll. Unicode
Implemented as CreateProcessW (Unicode) and CreateProcessA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.