Click here to Skip to main content
Click here to Skip to main content

Using VBScript and WMI to Access Vista's BcdStore

By , 1 Apr 2007
 

Introduction

Vista's BCD (Boot Configuration Data) replaces the boot.ini file used in previous Windows versions. The primary audience for this script is a system Administrator who needs to automate some aspect of how a Vista machine boots.

Microsoft does provide documentation on how to examine and update the BcdStore (i.e. the registry file that contains the BCD), but the information is spread over several sources. There are few decent examples of using VBScript to examine or update BcdStore information.

This script is intended as a working sample that can be used as a starting point to provide some automation. By replicating the output of the "bcdedit /enum active" command, people can see how to extract boot-related information.

Background

WMI is a large and complicated topic. For readers unfamiliar with WMI, I would recommend this  URL as a good introduction in what WMI is, and how to use it with VBScript.

Microsoft's documentation for BCD can be found in:

  1. Vista Software Development Kit
  2. MSDN Library, "Boot Configuration Data (BCD)" 
  3. "Boot Configuration Data in Windows Vista"

Using the Code

The script displays lines of text, similar to Vista's "bcdedit.exe" command line utility. Therefore the program should be run as a cscript:

cscript mimic_bcedit.vbs 

Alternatively, you can set your default scripting host to cscript by issuing the command:

cscript //h:cscript 

In this case, the leading cscript can be omitted when you run any .vbs file.

Points of Interest

The BCD stores logical drive information in the form:

\Device\HarddiskVolumeX 

Unfortunately there is no simple way (that I know of) to convert that to a drive letter (e.g. C:) using VBScript. The DDK function ZwQuerySymbolicLinkObject() can be used to obtain the drive letter from a \Device\HarddiskVolumeX reference.

History

  • Uploaded on April 1, 2007 - Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ross Johnston
Architect
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralResolving NT Device namesmemberalexvlas14 Apr '08 - 2:26 
The best and from my point of view the most legal way is to use MountManager:
Open the MntMgr control device with CreateFile("\\\\.\\MountPointManager")
and query mount points via DeviceIoControl(IOCTL_MOUNTMGR_QUERY_POINTS).
QuestionHow to VB.NET?memberstevenyoung1 Apr '07 - 15:29 
Your code is good, but how to do using VB.NET?
Thank you.
AnswerRe: How to VB.NET?memberthund3rstruck2 Apr '07 - 6:07 
Back when I used VB.NET the thing I loved was that VBScripts ran directly in VB.NET. If you want to use managed namespaces then you'll need to use the System.Management classes other wise you can just cut and paste into a new vb.net project and it should compile.
QuestionRe: How to VB.NET?memberstevenyoung2 Apr '07 - 12:10 
Could you please release it using VB.Net?
AnswerRe: How to VB.NET?memberthund3rstruck2 Apr '07 - 13:01 
I'm not the author... I was just commenting on your comment.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 1 Apr 2007
Article Copyright 2007 by Ross Johnston
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid