#include <windows.h>
#include <stdio.h>
//创建一个新窗口进程并返回进程ID号和进程的主线程ID号
int main()
{
STARTUPINFO si = {sizeof(si)};
char* szCommandLine = "cmd.exe";
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
PROCESS_INFORMATION pi;
BOOL bRet = ::CreateProcess(NULL,szCommandLine,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
if(bRet)
{
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
printf("进程ID号:%d\n",pi.dwProcessId);
printf("主线程ID号:%d\n",pi.dwThreadId);
}
return 0;
}