【问题标题】:A command in a .bat file is unrecognized when the .bat file is called from an Inno Setup but works fine when I run the bat file manually从 Inno Setup 调用 .bat 文件时无法识别 .bat 文件中的命令,但当我手动运行 bat 文件时工作正常
【发布时间】:2020-08-31 14:56:28
【问题描述】:

我有以下 .bat 文件:

fbwfmgr /enable
.
.
.
fbwfmgr /addexclusion c: "some folder 1"
fbwfmgr /addexclusion c: "some folder 2"
.
.
.

我从 Inno 设置中的 [Run] 部分调用,如下所示:

Filename: "{tmp}\set_write_protection_rules.bat";

我也试过这个:

Filename: "{cmd}"; Parameters: "/c ""{tmp}\set_write_protection_rules.bat""";    

我总是收到消息

'fbwfmgr' 不是内部或外部命令、可运行程序或批处理文件。

如果我通过双击运行 .bat 文件,它可以工作,如果我自己从 cmd 窗口运行它,它可以工作。我在这里错过了什么?

我在以管理员身份登录的 Windows Embedded Standard x64 系统上运行它。


编辑:

将完整路径添加到fbwfmgr.exe 并不能解决问题(我还手动查看了fbwfmgr.exe 的实际位置):

%systemroot%\system32\fbwfmgr.exe /enable

我发现a similar thread here 在从 vbs 运行 .bat 文件时 OP 遇到了同样的问题,那里似乎没有找到解决方案。从那里削减中间人的建议中,我尝试使用以下行直接从 Inno Setup 调用 fbwfmgr

Filename: "{cmd}"; Parameters: "c/ ""fbwfmgr /enable""";

但没有用。它只是打开一个空的控制台窗口。当我尝试从那里拨打fbwfmgr 时,无法识别。

【问题讨论】:

  • 什么是fbwfmgr?它来自哪里?

标签: batch-file inno-setup


【解决方案1】:

不是吗,因为系统上C:\Windows\System32中只有64位版本的fbwfmgr

作为 32 位应用程序中的 Inno Setup,它默认为 gets redirected to C:\Windows\SysWOW64C:\Windows\System32 的 32 位版本)。如果C:\Windows\SysWOW64 中没有fbwfmgr 的32 位版本,Inno Setup 将找不到它。

添加 Flags: 64bit 以使 Inno Setup 找到 fbwfmgr 的 64 位版本。

此外,通过命令解释器 (cmd.exe) 运行 .exe 应用程序毫无意义。

[Run]
Filename: "fbwfmgr.exe"; Parameters: "/enable"; Flags: 64bit

使用批处理文件,机制会稍微复杂一些。默认情况下,Inno Setup(作为 32 位应用程序)运行 32 位 cmd.exe,而后者又会查看 C:\Windows\SysWOW64。如果添加Flags: 64bit,Inno Setup 将运行一个 64 位的cmd.exe,它将查看C:\Windows\System32

[Run]
Filename: "{tmp}\set_write_protection_rules.bat"; Flags: 64bit

或使用64-bit install mode


如需类似问题,请参阅PowerShell script executed from Inno Setup is failing with "Retrieving the COM class factory for component with CLSID {XXXX} failed - error 80040154"

【讨论】:

    【解决方案2】:

    您可能需要提供fbwfmgr 的路径。

    例如

    "C:\Users\JOHNDOE\SomeDir\fbwfmgr“

    注意

    您几乎肯定也需要以管理权限运行批处理脚本!我知道你说你是以管理员身份登录的,但你需要确定你有运行脚本的权限,尤其是当你从另一个应用程序运行它时,(inno)

    【讨论】:

    • 这没有帮助,我已经编辑了帖子以反映这一点。在旁注中,为什么有人在没有测试它是否真的有效的情况下支持你的答案?
    • 您能否更新您的代码以反映它,以便我们可以准确地看到您现在尝试了什么!
    猜你喜欢
    • 2021-11-23
    • 2018-09-07
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2017-04-23
    • 2018-08-25
    • 2021-05-05
    • 2017-11-12
    相关资源
    最近更新 更多