WinExec函数,启动其他应用程序

简介: WinExec The WinExec function runs the specified application. Note  This function is provided only for compatibility with 16-bit Windows.

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,  // 可执行程序的路径,如"c:\\a.exe"
  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] Specifies how a Windows-based application window is to be shown and is used to supply the   wShowWindow  member of the   STARTUPINFO  parameter to the   CreateProcess function. For a list of the acceptable values, see the description of the   nCmdShow  parameter of the   ShowWindow  function. For a non-Windows – based application, the PIF file, if any, for the application determines the window state.

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:

Value Meaning
0 The system is out of memory or resources.
ERROR_BAD_FORMAT The .exe file is invalid.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The 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", ...)
目录
相关文章
|
2月前
|
Java Linux Shell
进程的程序替换(exec函数)【Linux】
进程的程序替换(exec函数)【Linux】
|
11月前
Qt通过QProcess启动进程并传递命令行参数
Qt通过QProcess启动进程并传递命令行参数
476 0
|
网络安全
服务器初始化及内核调优脚本
服务器初始化及内核调优脚本
|
Linux 调度
【操作系统】进程的创建与销毁
【操作系统】进程的创建与销毁
【操作系统】进程的创建与销毁
Qt窗口关闭和应用程序停止是否调用析构函数的一些说明
Qt窗口关闭和应用程序停止是否调用析构函数的一些说明
Qt窗口关闭和应用程序停止是否调用析构函数的一些说明
|
存储 编译器 C语言
Win知识 - 程序是怎样跑起来的——函数调用机制
Win知识 - 程序是怎样跑起来的——函数调用机制
82 0
Win知识 - 程序是怎样跑起来的——函数调用机制
|
API C++ Windows
C++中运行外部程序
关于三个SDK函数: WinExec, ShellExecute,CreateProcess 的其他注意事项: 【1】定义头文件 必须定义以下两个头文件: #include  // 可替换为 windows.h #include  如果定义了头文件 #include 的话就不必定义 #include 了。
1616 0
|
C#
C#让应用程序只运行一个实例的几种方法
一 判断是否有相同的实例已经运行 1 根据“Mutex”判断是否有相同的实例在运行 /// 已有实例运行返回true,否则为falsepublic bool IsRunningProcessByMutex(){     bool createNew;     using (System.
875 0