1. 程式人生 > WINDOWS開發 >WIN32建立程序CreateProcess

WIN32建立程序CreateProcess

BOOL CreateProcess(

LPCTSTR 【lpApplicationName】,//指向可執行模組名稱的指標
LPTSTR 【lpCommandLine】,//指向命令列字串的指標
LPSECURITY_ATTRIBUTES 【lpProcessAttributes】,//指向程序安全屬性的指標
LPSECURITY_ATTRIBUTES 【lpThreadAttributes】,//指向執行緒安全屬性的指標
BOOL 【bInheritHandles】,//處理繼承標誌
DWORD 【dwCreationFlags】,//建立標誌
LPVOID 【// pointer to new environment block】,
//指向新的環境塊 LPCTSTR 【lpCurrentDirectory】,//指向當前目錄名稱的指標 LPSTARTUPINFO 【lpStartupInfo】,//指向STARTUPINFO的指標 LPPROCESS_INFORMATION 【lpProcessInformation】 //指向PROCESS_INFORMATION的指標 );

// Process0617.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

void
Getsi() { STARTUPINFO si; GetStartupInfo(&si); printf("%x %x %x %x %x %x %x %x ",si.dwX,si.dwY,si.dwXCountChars,si.dwYCountChars,si.dwFillAttribute,si.dwXSize,si.dwYSize,si.dwFlags); } BOOL CreateProcessFun(PTCHAR szAppName,PTCHAR szCmdLine) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(
&si,sizeof(si)); ZeroMemory(&pi,sizeof(pi)); //si->cb = sizeof(si); si.cb = sizeof(si); if (!CreateProcess(szAppName,szCmdLine,NULL,FALSE,0,&si,&pi)) { printf("建立程序失敗\n"); return FALSE; } else { printf("建立程序成功,程序控制代碼:%d--程序ID:%d--執行緒控制代碼:%d--執行緒ID:%d\n",pi.hProcess,pi.dwProcessId,pi.hThread,pi.dwThreadId); return TRUE; } return TRUE; } int main(int argc,char* argv[]) { TCHAR stcAppName[] = TEXT("C://Program Files//Internet Explorer//iexplore.exe"); TCHAR stcCmdLine[] = TEXT(" https://www.qq.com/"); CreateProcessFun(stcAppName,stcCmdLine); getchar(); return 0; }