'bcdedit' is not recognized in compiled batch file

Convert your BATch files into EXEcutable format in one click.
assuretech
Posts: 5
Joined: Mon Jul 02, 2012 5:33 am

'bcdedit' is not recognized in compiled batch file

Post by assuretech »

I am having trouble compiling a batch file that uses the bcdedit command. The command string that is giving me trouble is as follows:

Code: Select all

if %WINMAJOR% gtr 5 (  
  bcdedit /set {current} safeboot network
) else (
  bootcfg /raw "/noexecute=AlwaysOff /fastdetect /safeboot:network" /id 1
)
This code block is for automatically booting the machine into safe-mode. If the ver command detects greater than 5 (Vista and Windows 7), it runs bcdedit. If it detects version 5 (Windows XP), it runs bootcfg.

If I run "bcdedit /set {current} safeboot network" in a terminal, it completes successfully. When I compile this bcdedit command string with Quick Batch File Compiler, I get the following error: "'bcdedit' is not recognized as an internal or external command, operable program or batch file."

All other commands in %SYSTEMROOT% I have tried to compile run successfully. I even tried to compile just the bcdedit command in a batch file with nothing else and after it is compiled, I still get the same error, and yet this command runs successfully when executed on the command line. I checked to see if bcdedit was running with abnormal permissions/security settings, and it is set no differently than any other file I tried that runs successfully. I tested this compiled bcdedit command string on more than one machine running both Windows Vista and 7 and I get the same results.

Does anyone know of a workaround to get this bcdedit command to run correctly in a compiled batch file?
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Post by support »

Perhaps this command requires administrator privileges?
assuretech
Posts: 5
Joined: Mon Jul 02, 2012 5:33 am

Post by assuretech »

I start the compiled .exe by choosing "run as administrator" and still no luck. I am completely stumped why this stubborn bcdedit is the only command I cannot run successfully in a compiled batch file. I tried a half-dozen different computers and virtual machines to make sure it was not a corrupted file, and I still receive the same odd results where this command is not recognized when run from a compiled .exe.
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Post by support »

Try the full path:

%WINDIR%\System32\bcdedit.exe
assuretech
Posts: 5
Joined: Mon Jul 02, 2012 5:33 am

Post by assuretech »

I still get the same error when setting the path to bcdedit, either with PATH=C:\Windows\system32 or calling the command with C:\Windows\system32\bcdedit.exe.

The only workaround I found is importing the following into the registry:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"
"PSScriptOrder"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0]
"Script"="C:\\Windows\\Temp\\_bugsquasher_\\bcdedit_safemode_on.cmd"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"
"PSScriptOrder"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0]
"Script"="C:\\Windows\\Temp\\_bugsquasher_\\bcdedit_safemode_on.cmd"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
bcdedit_safemode_on.cmd contains "bcdedit /set {current} safeboot network"

and then using the following to remove the temp. workaround:

First off, safemode is turned off with:
bcdedit_safemode_off.cmd contains "bcdedit /deletevalue {current} safeboot"

and the temp. registry entries are deleted:

Code: Select all

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0" /f
I tried another compiler and get the same error, so it is not anything to do with QBFC after-all. It seems to be something inherit with this bcdedit command.
Last edited by assuretech on Sat Jul 07, 2012 4:19 am, edited 1 time in total.
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Post by support »

Do you have 64-bit Windows?
assuretech
Posts: 5
Joined: Mon Jul 02, 2012 5:33 am

Post by assuretech »

I get the same error with both 32-bit and 64-bit Windows operating systems. This bcdedit error is consistent across every machine I have tested so far on Windows 7 (build 7600/7601) and Windows 8 Release Preview (build 8400).
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Post by support »

I found same error descriptions at Google, but no working solution.
assuretech
Posts: 5
Joined: Mon Jul 02, 2012 5:33 am

Post by assuretech »

I want to clarify that my above mentioned Group Policy "workaround" does not work after-all. It will boot the Windows 7/8 machine into Safe Mode, but then the reverse process to turn Safe Mode off does not initialize in Safe Mode.

It seems as if the Windows Registry does not load certain keys in Safe Mode. Normally prefixing an "*" in front of the RunOnce key name will work such as

Code: Select all

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v *Safe_Mode_Off /t REG_EXPAND_SZ /d %SYSTEMROOT%\Temp\_bugsquasher_\bcdedit_safemode_off.cmd /f
but in the case of bcdedit, this does not work.

Perhaps I need to submit a bug report to Microsoft Support since this appears to be a glitch within their operating system.