分享

CreateProcess执行一个控制台程序,隐藏DOS窗口

 水中麒麟 2015-11-19
引用:

http://www.cnblogs.com/liuweilinlin/archive/2012/08/20/2647168.html


STARTUPINFO   StartupInfo;//创建进程所需的信息结构变量    
GetStartupInfo(&StartupInfo);    
StartupInfo.lpReserved=NULL;    
StartupInfo.lpDesktop=NULL;    
StartupInfo.lpTitle=NULL;    
StartupInfo.dwX=0;    
StartupInfo.dwY=0;    
StartupInfo.dwXSize=0;    
StartupInfo.dwYSize=0;    
StartupInfo.dwXCountChars=500;    
StartupInfo.dwYCountChars=500;    
StartupInfo.dwFlags=STARTF_USESHOWWINDOW;    
StartupInfo.wShowWindow=SW_HIDE;    
//说明进程将以隐藏的方式在后台执行    
StartupInfo.cbReserved2=0;    
StartupInfo.lpReserved2=NULL;    
StartupInfo.hStdInput=stdin;    
StartupInfo.hStdOutput=stdout;    
StartupInfo.hStdError=stderr;    
PROCESS_INFORMATION   piProcess;    
BOOL   bRet;    
bRet   =   CreateProcess(modName,NULL,NULL,NULL,TRUE,CREATE_NO_WINDOW ,NULL,NULL,&StartupInfo,&piProcess);   
if(bRet)    
CloseHandle(piProcess.hThread);        
CloseHandle(piProcess.hProcess); 
注意其中的StartupInfo.dwFlags=STARTF_USESHOWWINDOW;是必须的,要不然showwindow的参数将无效,详细的MSDN上写得清楚

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多