A command in a .bat file is unrecognized when the

2019-02-20 10:25发布

问题:

I have the following .bat file:

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

which I'm calling from the [Run] section in my Inno Setup like this:

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

I have also tried this:

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

I always get the message

'fbwfmgr' is not recognized as an internal or external command, operable program or batch file.

If I run the .bat file by double clicking on it it works, if I run it from a cmd window myself it works. What am I missing here?

I'm running this on a Windows Embedded Standard x64 system logged in as the administrator.


EDIT:

Adding the full path to the fbwfmgr.exe does not solve the issue (I have also manually looked that that's the actual location of fbwfmgr.exe):

%systemroot%\system32\fbwfmgr.exe /enable

I found a similar thread here where the OP is having the same problem while running the .bat file from vbs, no solution seems to have been found there. From a suggestion there to cut the middle man I've tried calling fbwfmgr directly from Inno Setup with the following line:

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

but to no use. It just opens an empty console window. When I try to call fbwfmgr from there, it is not recognized.

回答1:

Isn't it, because there's only 64-bit version of the fbwfmgr in the C:\Windows\System32 on the system?

As Inno Setup in a 32-bit application, it by default gets redirected to C:\Windows\SysWOW64 (32-bit version of C:\Windows\System32). If there's no 32-bit version of fbwfmgr in the C:\Windows\SysWOW64, Inno Setup cannot find it.

Add the Flags: 64bit to make Inno Setup find 64-bit version of the the fbwfmgr.

Also, there's no point running a .exe application via a command interpreter (cmd.exe).

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

With a batch file, the mechanics is bit more complicated. Inno Setup by default (being a 32-bit applications) runs a 32-bit cmd.exe, which in turns looks into the C:\Windows\SysWOW64. If you add the Flags: 64bit, Inno Setup will run a 64-bit cmd.exe, which will look into the C:\Windows\System32.

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

Or use the 64-bit install mode.



回答2:

You probably need to provide the path to fbwfmgr.

e.g.

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

Note

You will almost certainly need to run the batch script with administrative privileges too! I know you said you are logged in as the administrator, but you need to be certain that you have the permission for the script to be running especially as you are running it from another application, (inno).