Jump to content

Recommended Posts

Posted

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.

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:

  Reveal hidden contents

 

Posted

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 ?

Posted

  On 2/12/2012 at 5:26 PM, 'wakillon said:

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)
Posted

@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.

Posted

  On 2/12/2012 at 7:02 PM, 'vacko said:

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.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...