C++启动其它exe程序的代码
来源:互联网 发布:sublime windows 编辑:程序博客网 时间:2024/05/18 00:09
先取到所要启动exe的绝对路径,比如: C:\Test\update.exe
也要得到exe所存在的目录路径,比如: C:\Test
1.先用Qt实现
QString path = "C:\\Test\\update.exe";QString runPath = "C:\\Test";QProcess *process = new QProcess;process->setWorkingDirectory(runPath);process->start("\"" + path + "\"");
但如果update.exe是有管理员权限的程序,那么上面的代码将无法运行起update.exe
有管理员权限的exe,就要用以下的代码。
2.用ShellExecuteEx
QString path = "C:\\Test\\update.exe";QString runPath = "C:\\Test";BPtr<char> updateFilePath = (char*)path.toStdString().c_str();BPtr<char> updateDirPath = (char*)runPath.toStdString().c_str();BPtr<wchar_t> wUpdateFilePath;BPtr<wchar_t> wUpdateDirPath;size_t size = os_utf8_to_wcs_ptr(updateFilePath, 0, &wUpdateFilePath);size_t size1 = os_utf8_to_wcs_ptr(updateDirPath, 0, &wUpdateDirPath);if (!size || !size1) throw string("Could not convert updateFilePath to wide");/* note, can't use CreateProcess to launch as admin. */SHELLEXECUTEINFO execInfo = {};execInfo.cbSize = sizeof(execInfo);execInfo.lpFile = wUpdateFilePath;execInfo.lpParameters = L"";execInfo.lpDirectory = wUpdateDirPath;execInfo.nShow = SW_SHOWNORMAL;if (!ShellExecuteEx(&execInfo)) { throw string("run exe fail");}
上面的os_utf8_to_wcs_ptr 是转宽字符串的。
阅读全文
0 0
- C++启动其它exe程序的代码
- Windows编程 - 启动可执行(exe)程序 代码(C++)
- windows C/C++ 在一个程序中打开,关闭和监视其它的exe程序
- C/C++怎么调用其它的exe
- 在程序中启动其它的程序
- c#Process.Start无法启动exe程序的问题
- c#Process.Start无法启动exe程序的问题
- 如何在MFC中启动其它的(.exe)可执行文件
- 四种启动其它程序的方法
- 四种启动其它程序的方法
- 四种启动其它程序的方法
- 四种启动其它程序的方法
- C#启动其它程序
- C程序启动代码分析
- windows下exe程序的启动过程
- Windows中.exe程序的启动过程和C/C++运行时库
- Windows中.exe程序的启动过程和C/C++运行时库
- Windows中.exe 程序的启动过程 和 C/C++运行时库
- JDBC连接MySQL数据库
- #算法# 递归法找多元素
- Guava LoadingCache使用记录
- 为什么经理、总监多是空降, 而不是从内部提拔?
- 多线程下载 断点续传
- C++启动其它exe程序的代码
- java并发编程实战:对象的共享笔记
- 求一个整数的平方根
- PDF里面复制出来的文章,在word里去掉回车符
- tcpdump
- mysql分布式数据库中间件对比
- 安全性测试-跨站脚本攻击测试方法和修改方法
- svn--2.安装
- Flink学习笔记:1、Flink快速入门