第一、第二個參數的用法:
例子:
使用ie打開指定的網頁。
注意第二個參數是 可執行文件+命令行參數
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE; //TRUE表示顯示創建的進程的窗口
TCHAR cmdline[] =TEXT("c://program files//internet explorer//iexplore.exe http://community.csdn.net/");
BOOL bRet = ::CreateProcess (
NULL,
cmdline, //在Unicode版本中此參數不能爲常量字符串,因爲此參數會被修改
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
int error = GetLastError();
if(bRet)
{
::CloseHandle (pi.hThread);
::CloseHandle (pi.hProcess);
printf(" 新進程的進程ID號:%d /n", pi.dwProcessId);
printf(" 新進程的主線程ID號:%d /n", pi.dwThreadId);
}
else
{
printf("error code:%d/n",error );
}
return 0;
}
也可如此:
第一個參數是 可執行文件;第二個參數是 命令行參數
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE; //TRUE表示顯示創建的進程的窗口
TCHAR cmdline[] =TEXT(" http://community.csdn.net/"); //注意前面有空格,否則打開的是主頁。
BOOL bRet = ::CreateProcess (
TEXT("c://program files//internet explorer//iexplore.exe"),
cmdline, //在Unicode版本中此參數不能爲常量字符串,因爲此參數會被修改
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
int error = GetLastError();
if(bRet)
{
::CloseHandle (pi.hThread);
::CloseHandle (pi.hProcess);
printf(" 新進程的進程ID號:%d /n", pi.dwProcessId);
printf(" 新進程的主線程ID號:%d /n", pi.dwThreadId);
}
else
{
printf("error code:%d/n",error );
}
return 0;
}