Deploying Windows 7 – Part 18: Determining the UUID of a Computer

If you would like to read previous articles in this series, please go to:

Tip:
You can find more information about automating LTI deployment in the Windows 7 Resource Kit from Microsoft Press. I am the lead author for this Resource Kit and I also maintain the Unofficial Support Site for the Windows 7 Resource Kit where you will find the latest updates and other useful information.

In Part 16 of this series you learned how to use the MDT database to customize the deployment of Windows 7 based on the UUID of each target computer. In that article you also learned how to use WMI to determine the UUID of a computer if this UUID is not displayed in the system’s BIOS or accompanying documentation. The method we used to do this however was a bit messy, plus the computer whose UUID you want to determine must already have had a Windows operating system installed on it.

This brings up a question: Can you use WMI to determine the UUID of a computer if there is no operating system installed on it? The answer is Yes. To do this, we first need to clean up the scripting stuff we did in the last two articles. Then we need to build a custom Windows Preinstallation Environment (WinPE) image, add the scripts to this image, and burn the image to CD media. You can then use this CD to boot a bare-metal computer into WinPE and run the script to determine the system’s UUID.  

And that’s what this present article and the next one are all about. First, in this article we’ll create a clean little script that will display a computer’s UUID without any fiddling around. Then in the next article we’ll learn how to create a customized WinPE “tools” CD you can use to run the script on a bare-metal system that has no operating system installed in order to determine the system’s UUID. Once you’ve used your WinPE CD to run the script on a number of target computers, you can enter these UUIDs into the MDT database and deploy customized Windows images to each computer as desired.

Tip: If you are new to WMI scripting, check out my 14-part introductory series of articles on WindowsNetworking.com titled Managing Windows Networks Using Scripts.

Script to Determine the UUID of a Computer

In Part 16 of this series we saw how we could determine the UUID of a computer using WMI as follows:

  1. We began with the DisplayClassProperties.vbs script from Part 13 of my earlier series of scripting articles that displays the names of all the properties of a WMI class together with the values of these properties.
  2. Next we ran WBEMTEST on the computer to determine how we need to customize the strWMIQuery = <string> line of our script so that the script will work on that particular computer. The actual steps to do this are: (a) run WBEMTEST (b) connect to root\cimv2 namespace (c) click Enum Instances (d) type Win32_ComputerSystemProduct (e) press OK. The resulting output from WBEMTEST is then used as the value of <string> in the above line of our script. And this must be done manually as WBEMTEST output doesn’t support copy to clipboard!
  3. Then once the script was customized, we ran it on the computer and included as part of the script’s output was the computer’s UUID.

This was all a bit messy of course—we’d rather not have to run WBEMTEST on the computer or have to customize the script each time we have to run it. And we’d rather just get the script to output the computer’s UUID and not a bunch of other stuff as well.

Here’s how we can do this. We’ll begin with the modified DisplayClassProperties.vbs script taken from Part 16 of this series:

‘ DisplayClassProperties.vbs
‘ Used to find the UUID of a specific desktop computer
‘ By Mitch Tulloch (www.mtit.com)
Option Explicit
On Error Resume Next
Dim strComputer
Dim strWMINamespace
Dim strWMIQuery
Dim objWMIService
Dim colItems
Dim objItem
strComputer = “.”
strWMINamespace = “\root\CIMV2”
strWMIQuery = “:Win32_ComputerSystemProduct.IdentifyingNumber=’MXG5380254 NA540′,Name=’PY196AV-ABA a1130e’,Version=’0n31211CT101AMBEM00′”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & strWMINamespace & strWMIQuery)
WScript.Echo “Number of properties of ” & strWMIQuery & ” class is ” & objWMIService.Properties_.count
For Each objItem in objWMIService.Properties_
    Wscript.Echo “Property: ” & objItem.name & vbTab & “Value: ” & objItem.value
Next

















Now, to accomplish what WBEMTEST does and return the instances of the Win32_ComputerSystemProduct class, we’ll need to use the SWbemServices.InstancesOf method of the SWbemServices object. To figure out how to do this, I simply adapted the following script from a page of the good old Windows 2000 Scripting Guide (see here):

strComputer = “.”
Set objSWbemServices = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colSWbemObjectSet = objSWbemServices.ExecQuery _
   (“SELECT * FROM Win32_Service”)
For Each objSWbemObject In colSWbemObjectSet
    Wscript.Echo “Name: ” & objSWbemObject.Name
Next





My customized version of the above script looks like this:

strComputer = “.”
Set objSWbemServices = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colSWbemObjectSet = objSWbemServices.ExecQuery _
   (“SELECT * FROM Win32_ComputerSystemProduct”)
For Each objSWbemObject In colSWbemObjectSet
   strIdentifyingNumber = objSWbemObject.IdentifyingNumber
   strName = objSWbemObject.Name
   strVersion = objSWbemObject.Version
Next
Wscript.Echo “IdentifyingNumber: ” & strIdentifyingNumber
Wscript.Echo “Name: ” & strName
Wscript.Echo “Version: ” & strVersion










The reason I need the above script to determine the values of the three properties IdentifyingNumber, Name and Version is because the Win32_ComputerSystemProduct class has three key properties, namely (you guessed it) IdentifyingNumber, Name and Version. To see this, refer to the documentation page for this class on MSDN. Remember that a key property is a property that provides a unique identifier for an instance of a class, and to connect to an instance of a class, you need to specify a particular instance by using the key property of the class. Key properties are marked with the “Key” qualifier in MSDN documentation—refer back to Part 13 of my earlier series of scripting articles for more information concerning key properties.

Now I simply need to merge the above customized script with my earlier DisplayClassProperties.vbs script in order to create the following new script which I’ve named UUID.vbs (note that I’ve simplified this script by omitting variable definitions and error handling):

‘UUID.vbs
‘Displays the UUID of a computer
‘By Mitch Tulloch (www.mtit.com)
strComputer = “.”
strWMINamespace = “\root\CIMV2”
Set objSWbemServices = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colSWbemObjectSet = objSWbemServices.ExecQuery(“SELECT * FROM Win32_ComputerSystemProduct”)
For Each objSWbemObject In colSWbemObjectSet
   strIdentifyingNumber = objSWbemObject.IdentifyingNumber
   strName = objSWbemObject.Name
   strVersion = objSWbemObject.Version
Next
strWMIQuery = “:Win32_ComputerSystemProduct.IdentifyingNumber='” & strIdentifyingNumber _
   & “‘,Name='” & strName & “‘,Version='” & strVersion & chr(39)
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & strWMINamespace & strWMIQuery)
For Each objItem in objWMIService.Properties_
    If objItem.name =  “UUID” Then
        Wscript.Echo objItem.name & ” = ” & objItem.value
    End If
Next


















Note that the tricky part here is making sure the quotes are correct in the strWMIQuery = <string> statement. For instance, the statement ends with & chr(39) which appends the single quote needed to properly complete the syntax of the statement. It took some fiddling to get this to work—the trick that helped me was to temporarily insert a Wscript.echo strWmiQuery statement immediately after the strWMIQuery = <string> statement so I could run the script and output the contents of the string to see whether the string had the correct syntax, then make a change and run the script again, and so on until I got the syntax right.

Testing the Script

Now let’s see if our script works by running it from the command-line on a computer that has Windows XP installed on it (Figure 1):


Figure 1: Running UUID.vbs on a computer that has an operating system

Let us make our script even easier to run by creating an accompanying batch file named UUID.bat that reads as follows:

@ECHO OFF
cscript.exe //nologo UUID.vbs

This makes it easier to run the script and also makes the output cleaner (Figure 2):


Figure 2: Running UUID.bat on a computer that has an operating system

Conclusion

Now that our script is ready, we need to build a WinPE image and include our script in this image so we can run our script on bare-metal systems. You will learn how to do this in the next article of this series.

If you would like to read previous articles in this series, please go to:

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top