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", ...)
目录
相关文章
|
存储 关系型数据库 MySQL
Nacos 配置数据持久化
Nacos 不仅仅可以作为注册中,还带有配置中心的功能。Nacos 配置默认存储在内存中,对于一些项目往往配置项有成百上千个这些都是非常重要的。在这个场景下我们可以将配置保存到 MySQL 中。来持久化我们的配置,保证 Nacos 重新启动或者服务节点挂掉后配置不会丢失。 环境介绍:nacos-server-1.4.2
1864 0
Nacos 配置数据持久化
|
API
天气预报1天-中国气象局-地址查询版免费API接口教程
此接口提供中国气象局官方的当日天气信息,支持POST和GET请求,需提供用户ID、KEY、省份及具体地点。返回数据包括状态码、消息、天气详情等。示例中使用的ID与KEY为公共测试用,建议使用个人ID与KEY以享受更高调用频次。
3809 9
|
运维 负载均衡 算法
|
网络协议 Windows
Windows Server 2019 Web服务器搭建
Windows Server 2019 Web服务器搭建
1152 0
HCL(新华三模拟器)如何连接CRT及改界面颜色
HCL(新华三模拟器)如何连接CRT及改界面颜色
|
安全 Shell Linux
Webshell管理工具:AntSword(中国蚁剑)
中国蚁剑的下载、安装、详细使用步骤
17098 1
|
运维 Ubuntu 网络协议
Ubuntu系统下修改网卡IP地址
【7月更文挑战第3天】Ubuntu系统下修改网卡IP地址
5032 1
|
算法 Ubuntu Java
数据包完整性校验总结
为了保证分发的数据包的一致性,常常需要增加数据包校验码,这样可以减少因为传递过程中造成的数据包不能使用问题,比如jar包的__invalid distance code__问题。在开始讨论数据包校验码生成方法前,先了解一下基本概念。 # 核心技术 ## 哈希 哈希是一种不可逆的映射,可以将数据经过哈希算法计算得到一个哈希值,而无法再将该哈希值反映射得到原始的数据。一般来说,不同的数据得到的哈
3533 0
|
SQL 存储 Oracle
Flyway数据库脚本管理工具使用经验
在常见的敏捷开发过程中,迭代的更新频繁出现,每个迭代数据库脚本也经常会更新,为了更好地管理项目中的数据库脚本,下面为大家介绍一款数据库脚本管理工具Flyway,希望对大家有帮助!
2228 1
Flyway数据库脚本管理工具使用经验
|
SQL
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
805 1

热门文章

最新文章