首页 > 解决方案 > 'mblctr' 不是内部或外部命令、可运行程序或批处理文件。如何解决此问题?

问题描述

我在 vs 中创建了一个按钮来打开移动中心。当我运行代码时,它显示错误“mblctr”无法识别,但是当在 cmd 中运行“mblctr”时它工作正常。这是我的代码有人帮我

private: System::Void button21_Click(System::Object^  sender, System::EventArgs^  e) {
    //system("C:\\Windows\\System32\\mblctr.exe");
    system("mblctr");
 }

标签: c++cwinapi

解决方案


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.

推荐阅读