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!
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.
"
// 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.
"
相关文章推荐
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- Guestinfo.hbm(1)The markup declarations contained or pointed to by the document type declaration must be well-formed
- All bytes must be within the maximum size specified by CreateFileMapping
- All bytes must be within the maximum size specified by CreateFileMapping
- Question 41: Which of the following operators must be overloaded by function objects in the Standard Template Library?
- Why the shortcut created by my MSI install start the setup process again each time?
- "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."
- SQL写存储过程时报错 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex
- The AnimationClip 'Walk' used by the Animation component 'Pig' must be marked as Legacy.
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.
- 问题:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Be careful when you compare the GUID with a string
- 关于LinerrLayout问题,总是出现"LinearLayout" must be followed by the ' = ' character.
- TabHost添加3个及以上tab时报的异常(you must specify a way to create the tab content)及其他
- C#使用Create创建文件后,报The Process cannot access the file because it is being used by another process的异常
- error: Xcode not set up properly. You ..confirm the license agreement by running /usr/bin/xcodebuild