c++ - 'mblctr' 不是内部或外部命令、可运行程序或批处理文件。如何解决此问题?
问题描述
我在 vs 中创建了一个按钮来打开移动中心。当我运行代码时,它显示错误“mblctr”无法识别,但是当在 cmd 中运行“mblctr”时它工作正常。这是我的代码有人帮我
private: System::Void button21_Click(System::Object^ sender, System::EventArgs^ e) {
//system("C:\\Windows\\System32\\mblctr.exe");
system("mblctr");
}
解决方案
mblctr.exe 仅作为 64 位应用程序存在于 64 位 Windows 上。32 位应用程序看不到与 64 位应用程序相同的 System32 文件夹。您可以使用虚拟 sysnative 文件夹访问 32 位应用程序中的 64 位 System32 文件夹。
#include <shellapi.h>
...
INT_PTR ret = (INT_PTR) ShellExecute(NULL, NULL, TEXT("mblctr.exe"), 0, 0, SW_SHOW);
if (ret <= 32)
{
TCHAR buf[MAX_PATH];
GetWindowsDirectory(buf, MAX_PATH);
lstrcat(buf, TEXT("\\sysnative\\mblctr.exe")); // Hopefully this fits in MAX_PATH, you might want to check in a real program.
ShellExecute(NULL, NULL, buf, 0, 0, SW_SHOW);
}
它在 cmd.exe 中有效,因为您在手动启动时运行的是 64 位版本的 cmd。如果您运行 cmd.exe 的 32 位版本,它将失败:
Win+ R“命令”
C:\Users\Anders>%windir%\syswow64\cmd.exe
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Users\Anders>mblctr.exe
'mblctr.exe' is not recognized as an internal or external command,
operable program or batch file.
推荐阅读
- flutter - 为什么 firebase_firestore 安全规则不适用于文档读取
- javascript - 在 Google Maps JavaScript Api 中单击时,如何根据结果位置向标记动态添加信息?
- python - 在geojson文件中删除带有for循环的元素
- node.js - ORM 与 Knex.js 在 Angular/Express/Postgres DB 上协同工作
- apache - 使用 mod_rewrite 的重定向太多(最多一个重定向?)
- javascript - 如何遍历未确定的 JSON 密钥并用它发送消息?
- android - 如何将选项菜单(3 个点和/或操作图标)添加到选项卡式活动?
- android - 我无法在 android 11 上创建文件夹或共享图像
- prolog - Prolog 中的 99 瓶啤酒
- javascript - 未选中复选框输入时,页面内容恢复正常(与以前一样)