Abyssmedia.com Forum Index Abyssmedia.com
Abyssmedia Support Forums
 
  FAQ    Search    Memberlist    Usergroups   Register 
  Profile    Log in to check your private messages    Log in 

'bcdedit' is not recognized in compiled batch file

 
Post new topic   Reply to topic    Abyssmedia.com Forum Index -> Quick Batch File Compiler
View previous topic :: View next topic  
Author Message
assuretech



Joined: 02 Jul 2012
Posts: 5

PostPosted: Tue Jul 03, 2012 12:30 am    Post subject: 'bcdedit' is not recognized in compiled batch file Reply with quote

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:
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?
Back to top
support
Site Admin


Joined: 13 Feb 2004
Posts: 378

PostPosted: Tue Jul 03, 2012 7:14 am    Post subject: Reply with quote

Perhaps this command requires administrator privileges?
Back to top
assuretech



Joined: 02 Jul 2012
Posts: 5

PostPosted: Tue Jul 03, 2012 8:27 am    Post subject: Reply with quote

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.
Back to top
support
Site Admin


Joined: 13 Feb 2004
Posts: 378

PostPosted: Wed Jul 04, 2012 12:30 pm    Post subject: Reply with quote

Try the full path:

%WINDIR%\System32\bcdedit.exe
Back to top
assuretech



Joined: 02 Jul 2012
Posts: 5

PostPosted: Thu Jul 05, 2012 4:04 am    Post subject: Reply with quote

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:
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:
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
Back to top
support
Site Admin


Joined: 13 Feb 2004
Posts: 378

PostPosted: Fri Jul 06, 2012 12:48 pm    Post subject: Reply with quote

Do you have 64-bit Windows?
Back to top
assuretech



Joined: 02 Jul 2012
Posts: 5

PostPosted: Sat Jul 07, 2012 3:16 am    Post subject: Reply with quote

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).
Back to top
support
Site Admin


Joined: 13 Feb 2004
Posts: 378

PostPosted: Sat Jul 07, 2012 10:23 am    Post subject: Reply with quote

I found same error descriptions at Google, but no working solution.
Back to top
assuretech



Joined: 02 Jul 2012
Posts: 5

PostPosted: Sun Jul 08, 2012 4:36 am    Post subject: Reply with quote

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:
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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Abyssmedia.com Forum Index -> Quick Batch File Compiler All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2011 phpBB Group