Skip navigation

Adapting the Scripts

Downloads
20506.zip

You can adapt the scripts I provide in "VBScripting Solutions: Exploring the HKEY_LOCAL_MACHINE Registry Subtree" to meet specific needs. For example, you can modify ReadCPU.vbs to read OS information and adapt ReadCurStat.vbs to read subtree information.

Reading OS Information
In Windows 2000, you can access the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion subkey to read OS information, such as the OS’s product ID, version number, and registered user and organization. (In Windows NT, you can access the same information in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion subkey.) This information is useful, especially if you need to track down an OS on a large network of computers.

You can use ReadCPU.vbs as a template to create a script, ReadProdID.vbs, that accesses OS information. Listing 1 contains this script. ReadProdID.vbs uses the CurrentVersion subkey’s ProductID entry to programmatically read the OS’s product ID.

The code in ReadProdID.vbs is similar to the code in ReadCPU.vbs. ReadProdID.vbs defines the constant that holds the subkey you want to access, creates an instance of the WshShell object, uses the WshShell object’s RegRead method to read the target entry, then displays the result in a dialog box.

Reading Subtree Information
If you want to adapt ReadCurStat.vbs to access a different subkey but you’re unsure of the subtree in which the subkey resides, you can read the subtree information from the registry. For example, suppose that you weren’t sure of the subtree for the CascadeControlPanel subkey. Instead of hard-coding the subtree in the script with the code

Path = "HKCU\"

you can use the RegRead method to read the HkeyRoot entry by specifying

Path = Shell.RegRead(REG_STARTMENU & "CascadeControlPanel\HkeyRoot")

However, the HkeyRoot’s data type is REG_DWORD, so the returned value is a hexadecimal number. Thus, you need to use a Select Case statement to transform the returned hex number into the equivalent string. Callout A in Listing 2 highlights this Select Case statement. As the scripts ReadProdID.vbs and AdaptedReadCurStat.vbs show, adapting the code I’ve presented is fairly easy. By adapting the scripts, you can meet your specific needs.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish