
推荐于2016-12-04
展开全部
最简单的办法:
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);
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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询