c++ - 在 C++ 中尝试从 Windows 10 中的 UNC 运行 EXE。C++ 非常新
问题描述
我刚开始用 C++ 编写控制台应用程序。它会进行一些验证,然后需要找到并运行一个可执行文件,该可执行文件可以位于不同位置,具体取决于它的部署方式。所以大部分脚本都可以工作,甚至运行部分也可以根据操作系统和位置工作。如果它是本地的,它可以工作,如果它是 Windows 7,它似乎甚至可以在 UNC 上工作。但在 Windows 10 中,它只是退出了。
该脚本找到 exe 并从它所在的路径运行它。当我将应用程序创建为批处理文件并使用 popD 移动到工作目录的 exe 位置时,它可以工作,但我似乎无法在 C++ 中模仿该功能. 我已经尝试过SetCurrentDirectory
,但它不会带走我试图通过的字符串。
if (version >= minver)
{
std::string name = "testApp.exe";
std::string path = (fs::current_path().string());
for (const auto& entry : fs::recursive_directory_iterator(path))
{
std::string list = entry.path().string();
int found;
if ((found = list.find(name)) !=list.npos)
{
std::cout << list << std::endl;
\\This is the part that sometimes works and sometimes doesn't
system(list.c_str());
}
}
}
解决方案
所以从长远来看,我以错误的方式追查问题。感谢 LandStalker 开辟了一条更好的道路。我对模仿 popD 的看法是正确的,但很难以正确的方式实际工作。
我SetCurrentDirectory
然后ShellExecute
对程序名做了一个。
推荐阅读
- wordpress - 如何在 corcel / acf 上获取 ACF 组字段值?
- c++ - 如何从 C++ 中输入的输入中随机选择?
- python - 如何从这个 traccar 输出字典中打印单个项目?
- scala - GroupBy 并根据 Scala 中的另一个地图转换地图
- delphi - Delphi FMX (Android) - 如何在没有提取的情况下读取 zip 流中的文本文件?
- python - Python tkinter 使用按钮更改背景颜色
- java - 使用 JavaMail 将“mail.imaps.fetchsize”属性设置为大数字有什么影响?
- python - 如何使用列获取数据类型并创建字典
- azure - Azure AD B2C CORS 错误
- javascript - 如何将 iframe 高度设置为最大值而不是滚动?