当前位置:编程学习 > VC++ >>

(VC++编程中)运行exe文件的API函数是哪些

想用MFC做一个异形登陆器,之后运行一个EXE文件
答案:
最简单的办法:   
Winexec(filename,SW_Show);
稍微难一点的CreateProcess(),创建进程
给楼主个例子
CString str;
STARTUPINFO si;
PROCESS_INFORMATION pi;

// 调用的应用程序名
str = "Ping"; //"Ping.exe"

// zero out and initialize STARTUPINFO
memset( &si, 0, sizeof( si ) );
si.cb = sizeof( si );
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
if(CreateProcess(
NULL, // can be name of process unless
// batch file, else must be
// in command line:
(char*)LPCSTR(str), // command line
NULL,NULL, // security options
FALSE, // if true will inherit all
// inheritable handles
// from this process
NORMAL_PRIORITY_CLASS, // can also be HIGH_PRIORITY_CLASS
// or IDLE_PRIORITY_CLASS
NULL, // inherit this process's
// environment block
NULL, // specifies working directory
// of created process
&si, // STA RTUPINFO specified above
&pi // PROCESS_INFORMATION returned
)
)
{
// HANDLE pH = pi.hProcess;
// // wait until application is ready for input
// if ( !WaitForInputIdle( pH,1000 ) )
// {
// // send messages, etc.
// }
// kill process with 0 exit code
// TerminateProcess( pH, 0 );
}
else
{
AfxMessageBox( "Ping.exe 文件当前目录不存在!" );
}


还有第三种办法,API函数
ShellExecute(0, NULL,fullPathFileName, NULL, NULL, SW_RESTORE);

上一个:这个VC++编程名词“Public”的解释是什么?
下一个:想学习VC++编程,各位推荐一下学习道路呀!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,