c++ - “mblctr”不被识别为内部或外部命令、可操作程序或批处理文件。如何解决此问题?

标签 c++ c winapi

我在 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“cmd”

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.

关于c++ - “mblctr”不被识别为内部或外部命令、可操作程序或批处理文件。如何解决此问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54441021/

相关文章:

c - execv() 执行进程时,如何在 C 中杀死进程及其所有子进程?

c++ - 为什么extern可以应用于定义?

c++ - 通过 SYSTEMTIME 检查文件的 LastWriteTime 是昨天

c++ - 如何更改禁用按钮的外观和编辑控件?

c++ - 开关语句使用

c++ - typedef 的用例

c++ - 尝试在 Linux 上使用 Clang++ 编译 c++11 正则表达式教程时出错

c - 尽管 sem_close 调用成功,但 sem_open 在第二次运行程序时失败

c++ - 从进程监视器中隐藏的进程

c++ - 如何定义运算符以便将用户定义类型数组转换为基本类型数组?