Jump to content
Sign in to follow this  
Juvigy

WMI get product key (HP laptop)

Recommended Posts

Hi Guys,

I have converted a WMI vbs script to get the laptop serial number of a laptop.

How can i extend it to get the product number of the laptop as well ?

What i have so far is:

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2")

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure")

$arrResults = Execute("$objitem.SerialNumber")

On the HP site there is a CMD command that works:

wmic /namespace:\\root\wmi path MS_SystemInformation

It looks like a WMI but i cant get it to work in AutiIt.

Share this post


Link to post
Share on other sites

This is part of a VBScript that I use to get the computer information from a computer using WMI, if you're looking for the model number this will help.

Set objWMIService = GetObject("winmgmts:" & strIPAddr & "rootCIMV2")
 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
  For Each objItem In colItems
  strManuf = trim(objItem.Manufacturer)
   If strManuf = "Dell Computer Corporation" then
    strManuf = "Dell Inc."
   end if
      strModel = trim(objItem.Model)
   If strModel = "HP EliteBook 6930p" then
    strModel = "EliteBook 6930p"
   Elseif strModel = "HP Compaq dc7900 Small Form Factor" then
    strModel = "dc7900 SFFactor"
   End If
     Next

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I am not looking for the model number - i am looking for the "product number" - it is similar to the service tag / serial number.

objItem.SerialNumber

works , but

objItem.ProductNumber

doesnt work. Changing Win32_ComputerSystem to Win32_BIOS or Win32_SystemEnclosure doesnt help.

Share this post


Link to post
Share on other sites

What is the product number? I'm not familiar with that term in this regard.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

See this : http://h10025.www1.hp.com/ewfrf-JAVA/Doc/images/c02730919.gif

S/N = Serial Number

P/N = Product number

Share this post


Link to post
Share on other sites

Try this:

$system = @ComputerName

$objWMIService = ObjGet("winmgmts:" & $system & "rootWMI")
$colItems = $objWMIService.ExecQuery("SELECT * FROM MS_SystemInformation", "WQL", 0x30)

If IsObj($colItems) Then
    For $objItem in $colItems
        With $objItem
            $SystemProductName = .SystemProductName
            $SystemSKU = .SystemSKU
        EndWith
    Next
    MsgBox(0, "System Info", "System Product Name: " & $SystemProductName & @CRLF & _
                                                 "System SKU: " & $SystemSKU)
EndIf

Or another WMI method:

$system = @ComputerName

$objWMI= ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $system & "rootWMI")
$oItems = $objWMI.InstancesOf("MS_SystemInformation")

For $oTokens In $oItems
    $SystemProductName = $oTokens.SystemProductName
    $SystemSKU = $oTokens.SystemSKU
Next

MsgBox(0, "System Info", "System Product Name: " & $SystemProductName & @CRLF & _
                                             "System SKU: " & $SystemSKU)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

10x UEZ it works. Where can i get more info on

"rootWMI" , "rootcimv2" and the list of properties like .SystemSKU ?

Share this post


Link to post
Share on other sites

Sciptomatic is your friend ;) or try the built-in tool wbemtest

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...