您的位置:首页 > 其它

CreateProcess by modify the struct STARTUPINFO, sth you must be careful!!

2009-04-08 10:46 501 查看
 This is my first time write bolgs in English, if sth you cannot understand, you can tell me all the mistakes and contact me.Welcome and thanks!

 

// 02 CreateProcess.cpp : Defines the entry point for the console application.
//

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

void main(int argc, char* argv[])
{
//char szCommandline[]="notepad ReadMe.txt";
char szCommandline[]="cmd";
STARTUPINFO si={sizeof(si)};
PROCESS_INFORMATION pi;

si.dwFlags=STARTF_USESHOWWINDOW | STARTF_USEPOSITION | STARTF_USESIZE | STARTF_USEFILLATTRIBUTE;
si.wShowWindow=true;
si.dwX=0;
si.dwY=0;
si.dwXSize=500;
si.dwYSize=500;
si.dwFillAttribute=FOREGROUND_RED| BACKGROUND_RED| BACKGROUND_GREEN| BACKGROUND_BLUE;
si.lpTitle="Hello world!";
//通过对si的改变,运行的结果还是不变,请问为什么
//因为开始创建的进程“notepad”不是console process

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);
}

}


 

Be careful : everything  you want to change must be a console process.At first I create a process to open the .txt , no matter how I change the struct STARTUPINFO the process gives me the same result. Then I change the initiation of szCommandline from "notepad" to

"cmd",then everything changs. Just as it said in the MSDN "For console processes, this is the title displayed in the title bar if a new console window is created. If NULL, the name of the executable file is used as the window title instead. This parameter must be NULL for GUI or console processes that do not create a new console window.

"

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct null cmd file
相关文章推荐