MFC中执行其它应用程序

答一个网友所问,想在MFC中直接执行其它应用程序,诸如debug、notepad等等:

WinExec( " debug.exe " ,SW_SHOWNORMAL); 

以下是MSDN的内容:

WinExec

 

The WinExec function runs the specified application.

Note  This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.

 

UINT WinExec(
  LPCSTR lpCmdLine,
  UINT uCmdShow
);
Parameters
lpCmdLine
[in] Pointer to a null-terminated character string that contains the command line (file name plus optional parameters) for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence:
  1. The directory from which the application loaded.
  2. The current directory.
  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
  5. The directories listed in the PATH environment variable.
uCmdShow
[in] For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function.
Return Values

If the function succeeds, the return value is greater than 31.

If the function fails, the return value is one of the following error values.

Return code/valueDescription

0
The system is out of memory or resources.
ERROR_BAD_FORMATThe .exe file is invalid.
ERROR_FILE_NOT_FOUNDThe specified file was not found.
ERROR_PATH_NOT_FOUNDThe specified path was not found.
Remarks

The WinExec function returns when the started process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process started by a call to WinExec.

Security Remarks

 

The executable name is treated as the first white space-delimited string in lpCmdLine. If the executable or path name has a space in it, there is a risk that a different executable could be run because of the way the function parses spaces. The following example is dangerous because the function will attempt to run "Program.exe", if it exists, instead of "MyApp.exe".

 

WinExec("C://Program Files//MyApp", ...)

If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application.

To avoid this problem, use CreateProcess rather than WinExec. However, if you must use WinExec for legacy reasons, make sure the application name is enclosed in quotation marks as shown in the example below.

 

WinExec("/"C://Program Files//MyApp.exe/" -L -S", ...)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值