1. | Open \My Documents\Microsoft Press\VBScriptSBS\Templates\BlankTemplate.vbs in Microsoft Notepad or your favorite script editor. Save the script as YourNameReadTheRegistry.vbs.
|
2. | Add Option Explicit as the first line of your script.
|
3. | Declare the following variables: strKeyPath, strComputer, objReg, subKey, and arrSubKeys. The Header information section of your script will look like the following:
Option Explicit
Dim strKeyPath
Dim strComputer
Dim objReg
Dim subKey
Dim arrSubKeys
|
4. | Define a constant to be used for HKLM. Its hex value is &H80000002. Your code for this looks like the following:
|
5. | Assign the Software\Microsoft path to the strKeyPath variable. It will look like the following:
strKeyPath = "SOFTWARE\Microsoft"
|
6. | Assign the value of "." to the variable strComputer.
|
7. | Use the objReg variable to hold the SWbemServicesEx object. Connect into the root\default:stdRegProv namespace on the local computer. Your code to do this looks like the following:
Set objReg=GetObject("winmgmts:\\" &_
strComputer & "\root\default:StdRegProv")
|
8. | Now use the EnumKey method to read the subkeys found under the Software\Microsoft key. The Software\Microsoft key is located in the HKLM tree. Feed the results out into a variable called arrSubKeys. The code for this looks like the following:
objReg.EnumKey HKLM, strKeyPath, arrSubKeys
|
9. | Use WScript.Echo to echo out strKeyPath. This will be a header for the list of software contained in the Software\Microsoft key. You can use something like this:
WScript.Echo("Keys under " & strKeyPath)
|
10. | Use a For Each...Next loop to iterate through the subkeys that are contained in the arrSubKeys variable. Use WScript.Echo to echo out the subkeys. Use the subKey variable as your placeholder. Your code will look like the following:
For Each subKey In arrSubKeys
WScript.Echo vbTab & subKey
Next
|
11. | Save and run the program under CScript.exe to avoid a plethora of dialog boxes.
|