Sign in to follow this  
Followers 0
vacko

BCDedit function doesn't work

9 posts in this topic

Hello,

could you help to check what is wrong with my BCDedit function ? When I run it, no any new entry is added into BCD.

Even MsgBox doesn't return any GUID (actually I return 0, but this is error code of RUN function, right ?).

So, I think function doesn't work.

#include <Constants.au3>
#include <String.au3>

BCDaddVHD("c:\boot\BCD", "TEST")

Func BCDaddVHD($BCDstore, $BCDmodel)

$guidreturn = Run(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/create /d ' & $BCDmodel & ' /application OSLOADER', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWait ($guidreturn,5)

Do
    $line = StdoutRead($guidreturn) & StderrRead($guidreturn)
Until $line = not ""
$guid = _StringBetween($line, '{', '}')

RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} device vhd=[locate]\vhd\' & $BCDmodel & '.vhd', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} osdevice vhd=[locate]\vhd\' & $BCDmodel & '.vhd', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} path \Windows\system32\winload.exe', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} systemroot \Windows', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} detecthal Yes', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} locale en-US', "", @SW_HIDE)
RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/displayorder {' & $guid & '} /addlast', "", @SW_HIDE)
MsgBox(0,"Info", "Entry "&$BCDmodel&" with GUID " &$guid& " created")
EndFunc

I think some quotes are bad or missing, but because I'm just beginner with AutoIt, I don't know what rule I need follow and how to fix it.

Share this post


Link to post
Share on other sites



Try to add a space after each $BCDstore & '


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Just a few quick ideas to test:

Insert a space after each $BCDstore e.g.

$BCDstore & '/set ...
to
$BCDstore & ' /set ...
That's not only true for "/set" but for "/displayorder" too.

If BCDstore returns an exit code you can check tof this code:

$iResult = RunWait(@ComSpec & ' /c bcdedit /store ' & $BCDstore & '/set {' & $guid & '} device vhd=[locate]vhd' & $BCDmodel & '.vhd', "", @SW_HIDE)
If $iResult <> 0 Then ...
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks, we have some progress, I inserted spaces as advised, also changed

' & $BCDmodel & '

to

"' & $BCDmodel & '"

because entry name have to be in double quotes (it's required by BCDedit, I forgot this...).

So BCDedit /create now works (even physically add entry into BCD file),

but all other BCDedit commands doesn't work, because $guid return nothing (but not zero).

Any advise ?

Share this post


Link to post
Share on other sites

And _StringBetween return a 0 based $array[0] contains the first found string !


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

And _StringBetween return a 0 based $array[0] contains the first found string !

You are right, I tried remove ProcessWait ($guidreturn,5) and @ComSpec /c but no any significant effect.

$line returns: The entry {7ac016c3-5599-11e1-8da7-00261882441b} was sucessfully created.

But _StringBetween can't handle it and return nothing, so $guid is also empty.

Could you help to explain me on below example (or in my original code) how to solve it ?

#include <String.au3>
$line = "The entry {7ac016c3-5599-11e1-8da7-00261882441b} was sucessfully created."
$guid = _StringBetween($line, '{', '}')
MsgBox(1, "Info", "GUID is" & $guid)

Share this post


Link to post
Share on other sites

@wakillon: never mind, just found how to fix it...

Thanks to everybody, now it's functional.

BTW, is there any other way how to add entry into BCD ?

When compare my script (or my previously used .bat file) with EasyBCD, adding new entry take much more time.

Especially when I will need add 20 or more entries one-by-one.

Share this post


Link to post
Share on other sites

When compare my script (or my previously used .bat file) with EasyBCD, adding new entry take much more time.

Especially when I will need add 20 or more entries one-by-one.

EasyBCD is just a wrapper for bcdedit.exe just like your Autoit3 script.

If should not be faster, properly you used it on your system bcd store that is persistent inside the registry all the time

Using bcdedit.exe -store ... will load, unload and save the bcd hive to disk every time you call it, what takes a bit time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0