Wednesday, December 10, 2008

WMIC PRODUCT Returns Invalid Class Error 0x80041010

To say that I use WMI (and WMIC) on a daily basis is an understatement. It saves me so much time, but I did run into this bug which I wasted a little time on.

I remembered that there was a WMIC alias called PRODUCT which returned a lot of useful data about what software was installed on the Windows Server 2003 instance. However when I changed jobs from one organisation to another, this function no longer worked for me. I would get an error just like this one:

C:\WINDOWS\system32>wmic product
Node - Server1
ERROR:
Code = 0x80041010
Description = Invalid class
Facility = WMI

The solution was very simple. It turns out that the Windows Installer information is not available in WMI until you install an optional Windows component called "WMI Windows Installer Provider". This component can be installed through "Add/Remove Windows Components"... look for the "Management and Monitoring Tools" group.

If you plan on deploying this to a large fleet of servers, I would recommend you learn about a tool for enabling Windows components in an automated way. The Microsoft tool to do that is called SysOCMgr.exe and is described here. I might right some detailed stuff about SysOCMgr.exe later, so watch this space.

Monday, October 13, 2008

BIOS Serial Number as Computer name in Sysprep image

At a previous job about 18 months ago, I was asked to create a single SOE image that worked on many types of hardware, and was customizable to suit one of four organisations depending on which button the user clicked. It was an awesome challenge and I learned a lot from the experience.

One of the requirements of this Windows XP image was that the computer name of the machine had to be equal to that of the machine's serial number. That is, the hostname, and domain computer account, had to be exactly what your would yield if you used the WMIC command:

C:\> WMIC BIOS GET SerialNumber

I remember that this was quite difficult to achieve, and (for once) Google was of little assistance. There were a few hack 's suggested, like running a script on first start that would pull the value from WMI. But I was after a truely transparent experience which no user could stuff up, and which required no user intervention.

I did meet my deliverables on that project, and eighteen months down the track, I am writing this blog entry to you because it just occured to me that I probably should have shared this at the time to hopefully save people some time.

Setting the computer name to the machine's serial number in a sysprep build


1. Edit your sysprep.inf file and set the following value:


[UserData]
ComputerName=*COMPUTERNAME*

2. Copy and paste (and feel free to re-engineer my poor code) this into a file called GetSerialNumber.wsf


<job id="SetNameToSerial">
<script language="VBScript">
'Get Serial number from BIOS
Set objWMIService = GetObject("winmgmts:impersonationLevel=Impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)

FOR EACH item IN colItems
compname = item.SerialNumber
NEXT

'Edit sysprep.inf file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("sysprep.inf", 1)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "*COMPUTERNAME*", compname)
Set objFile = objFSO.OpenTextFile("sysprep.inf", 2)
objFile.WriteLine
strNewText
objFile.Close
</script>
</job>



3. Create a Winbom.ini file in preparation for a factory-mode sysprep (with mini-setup)

4. Use the [OEMRunOnce] secion to execute the script... The Winbom.ini file will look something *LIKE* this (I lost my copy!.. and CBF testing it):



[Factory]
Reseal = Reboot
ResealMode = Mini
WinbomType = Factory
UserName = Admin
Password = Password
[OEMRunOnce]
"Computername", "C:\windows\system32\wscript.exe GetSerialNumber.wsf"

5. You're done!

Now just do a factory mode sysprep.

Appologies that this probably wont work out of the box, as I havn't looked at this kind of stuff for 18+ months. I hope it helps. I'm sure this has been achieved by others, but when I needed the method, nobody had documented. I hope I've given you enough info to point you in the right direction. Good luck.

P.S. If you see people on the forums having trouble with this, send them my way :D