Jump to content


A.Kassem

Import HP warranty info from registry

Recommended Posts

I want to add Workstations and Laptops warranty info to registry so I can import it to SCCM current branch

I used the following script it seems to work fine but when checking info in registry only device S/N and P/N with no warranty end or start info there I guess it was for old HP warranty site I replaced site with new one in script but still no luck can anyone help to get it to work

'//----------------------------------------------------------------------------
'// Purpose: Check Warranty Information for HP Computers
'// Usage: cscript HP.vbs
'// Original Version: 1.1 - April 23, 2014 - Odd-Magne Kristoffersen
'// Script taken from: https://sccmguru.wordpress.com/2014/04/24/hp-and-lenovo-warranty-information-in-configuration-manager-2012-r2/
'// edited by Bernhard Sommer October 24, 2016
'//
'//------------------------!!Attention!!-------------------------------------
'// This script does NOT work for Enterprise Products
'//------------------------!!Attention!!-------------------------------------
'//
'// This script is provided "AS IS" with no warranties
'//
'//----------------------------------------------------------------------------
On Error Resume Next
'//----------------------------------------------------------------------------
'// Return Codes
'// 7 = Could not open the website, maybe proxy server is wrong.
'// 4 = An unknown error Occured while opening the website.
'// 5 = MSXML Version not found
'//----------------------------------------------------------------------------

'//----------------------------------------------------------------------------
'// Variable Declarations
'//----------------------------------------------------------------------------

EnableLogging = True
'Insert your Company Name
sCompanyName = "Company"

'Insert Proxy Server and Port
'If no Proxy Server is used just leave "" there

sProxyServer = ""
sProxyPort = ""

'//----------------------------------------------------------------------------
'// Set Logging Information
'//----------------------------------------------------------------------------

Set oShell = CreateObject("wscript.Shell")
Set fso = CreateObject("scripting.filesystemobject")
If EnableLogging Then
    Set oLogFile = fso.OpenTextFile("c:\windows\temp\WarrantyInfo.log", 8, True)
    oLogFile.WriteLine "*********************************************************"
End If

'//----------------------------------------------------------------------------
'// Set Warranty WebSite Variables
'//----------------------------------------------------------------------------

sWebServiceHost = "http://h20566.www2.hp.com/hpsc/wc/public/find"
sWebService = sWebServiceHost

'//----------------------------------------------------------------------------
'// Set Proxy
'//----------------------------------------------------------------------------

'WriteLog "Checking Proxy"

'get User
'sUsername = CreateObject("WScript.Network").UserName
'sUserDomain = CreateObject("WScript.Network").UserDomain
'WriteLog "Current User is : " & sUserDomain & "\" & sUsername 

'//----------------------------------------------------------------------------
'// Create Objects
'//----------------------------------------------------------------------------

Dim objShell
Set objShell = CreateObject("WScript.Shell")

const HKLM = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
'//----------------------------------------------------------------------------

'objShell.RegWrite "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable","0","REG_DWORD"
'Const HKEY_CURRENT_USER = &H80000001
'Const HKU = &H80000003
'If sUsername = "SYSTEM" then
'	dwvalue=objShell.RegRead ("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
'Else
'	dwvalue=objShell.RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
'End If
'If dwValue = 1 Then
'	WriteLog "Proxy is enabled"
'Else
'	WriteLog "Proxy is disabled"
'	WriteLog "Setting Proxy"
'	If sUsername = "SYSTEM" then
'		objShell.RegWrite "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable","1","REG_DWORD"
'		objShell.RegWrite "HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", sProxyServer & ":" & sProxyPort
'		dwvalue=objShell.RegRead ("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
'	Else
'		objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable","1","REG_DWORD"
'		objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", sProxyServer & ":" & sProxyPort
'		dwvalue=objShell.RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
'	End If
'	If dwValue = 1 Then
'		WriteLog "Proxy was successfully enabled"
'	Else
'		WriteLog "Proxy could not be set"
'		WriteLog "Exit Warranty Check"
'		oLogFile.WriteLine "*********************************************************"
'		oLogFile.Close
'		wscript.quit(1)
'	End If
'End If

'//----------------------------------------------------------------------------
'// Get the system's serial number from WMI
'//----------------------------------------------------------------------------

WriteLog "Beginning warranty information lookup."
Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select SerialNumber from Win32_BIOS",,48)
For Each objItem in colItems
    sSerialNumber = objItem.SerialNumber
Next
'sSerialNumber =""
WriteLog "Serial number of system is " & sSerialNumber

'//----------------------------------------------------------------------------
'// Get the Product ID from WMI
'//----------------------------------------------------------------------------

Const wbemFlagReturnImmediately = 16
Const wbemFlagForwardOnly = 32
lFlags = wbemFlagReturnImmediately + wbemFlagForwardOnly
strService = "winmgmts:{impersonationlevel=impersonate}//./root/HP/InstrumentedBIOS"
strQuery = "select * from HP_BIOSSetting"
Set objWMIService = GetObject(strService)
Set colItems = objWMIService.ExecQuery(strQuery,,lFlags)
sPN = ""
For Each objItem In colItems
    If objItem.Name = "SKU Number" Then
        sPN = objItem.Value
    End If
    If objItem.Name = "Product Number" Then
        sPN = objItem.Value
    End If
Next
'sPN=""
'//-----------------------
'// Get left part of PN
'//-----------------------
sPNLeft = LEFT(sPN,7)
'sPNLeft = ""
'WriteLog "PN Left : " & sPNLeft
'//-----------------------
'// Detect if PN contains #
'// Because some products do not contain it
'//-----------------------
sPNRaute = RIGHT(sPN, 4)
sPNRaute = LEFT(sPNRaute, 1)
'WriteLog "Raute = " & sPNRaute
if sPNRaute = "#" Then
	sPNRight = RIGHT(sPN, 3)
	'WriteLog "PN Right : " & sPNRight
	sProductNumber = sPNLeft & "%23" & sPNRight
Else
	sPNRaute = "" 
	sPNRight = ""
	sProductNumber = sPNLeft
End If
'WriteLog "PN Right " & sPNRight

If Len(sProductNumber) = 0 Then
    WriteLog "ERROR: Product Number could not be determined."
    'oLogFile.WriteLine "*********************************************************"
    'oLogFile.Close
    'WScript.Quit(9)
Else
    WriteLog "Product number of the system is " & sPNLeft & sPNRaute & sPNRight
End If

'//----------------------------------------------------------------------------
'// Get the OS Architecture
'//----------------------------------------------------------------------------
sAddressWidth = "32"
Set colItems = oWMIService.ExecQuery("Select AddressWidth from Win32_Processor",,48)
For Each objItem in colItems
    sAddressWidth = objItem.AddressWidth
Next

WriteLog "Operating system is " & sAddressWidth & " bit."

'//----------------------------------------------------------------------------
'// Define the parameters string to send to the web site
'//----------------------------------------------------------------------------

sParameters = "rows%5B0%5D.item.productNumber=" & sProductNumber & "&rows%5B0%5D.item.countryCode=AT&submitButton=Senden&rows%5B0%5D.item.serialNumber=" & sSerialNumber & "&hpeuck_locale_ar=at&lang=de"

WriteLog "Opening the web site URL " & sWebService & "?" & sParameters

'//----------------------------------------------------------------------------
'// Define and call the web site
'//----------------------------------------------------------------------------

'dwvalue=objShell.RegRead ("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
'If dwvalue = 1 then
'	WriteLog "Proxy still enabled"
'Else
'	WriteLog "Proxy is disabled"
'	oLogFile.WriteLine "*********************************************************"
'	oLogFile.Close
'	wscript.quit(1)
'End If
'// Check MSXML Version
'set xmlhttp = createobject ("msxml2.xmlhttp.3.0")
rMSXMLVer=objShell.RegRead ("HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.6.0\")
If Err.Number = 0 then
	WriteLog "Setting MSXML Version to : " & rMSXMLVer
	sMSXMLVer = "MSXML2.ServerXMLHTTP.6.0"
	Err.Clear
Else
	Err.Clear
	rMSXMLVer=objShell.RegRead ("HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.3.0\")
	If Err.Number = 0 then
		WriteLog "Setting MSXML Version to : " & rMSXMLVer
		sMSXMLVer = "MSXML2.ServerXMLHTTP.3.0"
		Err.Clear
	Else
		wscript.echo "Error : MSXML Version not found"
		wscript.quit(5)
	End If
End If
set xmlhttp = CreateObject(sMSXMLVer)
If sProxyServer = "" then
	WriteLog "No Proxy Sever used"
Else
	WriteLog "Proxy Sever : '" & sProxyServer & ":" & sProxyPort &"' is used"
	xmlhttp.setProxy 2, sProxyServer & ":" & sProxyPort
End If
Err.Clear
 xmlhttp.open "GET", sWebService & "?" & sParameters, false
 xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 xmlhttp.send
 If Hex(Err.Number) = "80072EE2" Then
    WriteLog "Could not open the website, maybe proxy server is wrong."
    oLogFile.WriteLine "*********************************************************"
    oLogFile.Close
    wscript.quit(7)	
End If
If Err.Number <> 0 then
	WriteLog "Warning: An unknown error Occured while opening the website."
	WriteLog "Error: " & Err.Number
	WriteLog "Error (Hex): " & Hex(Err.Number)
	WriteLog "Source: " &  Err.Source
	WriteLog "Description: " &  Err.Description
	oLogFile.WriteLine "*********************************************************"
	oLogFile.Close
	wscript.quit(4)
End IF
 If xmlhttp.Status = 200 Then
    WriteLog "Successful response from the web site."
    Process xmlhttp.ResponseText
Else
    WriteLog "ERROR: the web site returned status code " & xmlhttp.Status
    WriteLog "Returning exit code 1."
    nExitCode = 1
End If

If EnableLogging Then
    oLogFile.WriteLine "*********************************************************"
    oLogFile.Close
End If

'//----------------------------------------------------------------------------
'// Functions
'//----------------------------------------------------------------------------
 
 Function Process (HTML)
    WriteLog "Processing the HTML returned from the site."

    If sAddressWidth = 32 Then
	sRegistryKey ="SOFTWARE\"
    Else
	sRegistryKey = "SOFTWARE\"
    End If
    sKeyPath = sRegistryKey & sCompanyName & "\WarrantyInformation"
    
    WriteLog "Registry key path is HKLM\" & sKeyPath
    
    oReg.CreateKey HKLM,sKeyPath
 
    WriteLog "Setting registry values."
	
'	SerialNumber = split(xmlhttp.responseText,"Serial number")(1)
'	SerialNumber = split(SerialNumber,"</td></tr>")(0)
'	SerialNumber = replace(replace(SerialNumber,vbcr,""),vblf,"")
'	SerialNumber = split(SerialNumber,"bottomSpaceBig")(1)
'	SerialNumber = split(SerialNumber,">")(1)
	WriteLog "Serial Number is : " & sSerialNumber
	oReg.SetStringValue HKLM, sKeyPath, "SerialNumber", sSerialNumber
    
'    ProductNumber = split(xmlhttp.responseText,"Product number")(1)
'    ProductNumber = split(ProductNumber,"</td></tr>")(0)
'    ProductNumber = replace(replace(ProductNumber,vbcr,""),vblf,"")
'    ProductNumber = split(ProductNumber,"bottomSpaceBig")(1)
'    ProductNumber = split(ProductNumber,">")(1)
    WriteLog "Product Number is : " & sPNLeft & sPNRaute & sPNRight
    oReg.SetStringValue HKLM, sKeyPath, "ProductNumber", sPNLeft & sPNRaute & sPNRight
	
    WarrantyCheckDate = Right("0" & Day(Date), 2) & "." & Right("0" & Month(Date), 2) & "." & Year(Date)
    WriteLog "Warranty Check Date is : " & WarrantyCheckDate
    oReg.SetStringValue HKLM, sKeyPath, "WarrantyCheckDate", WarrantyCheckDate
'//----------------------------------------------------------------------------
'// Get Care Pack or Basic Warranty
'//----------------------------------------------------------------------------
CarePack = split(xmlhttp.responseText,"hpui-normal-row")(1)
'wscript.echo Carepack
CarePack = split(CarePack,"rowspan")(1)
CarePack = split(CarePack,">")(1)
CarePack = split(CarePack,"<")(0)

If CarePack = "HP Care Pack" Then
	WriteLog "Carepack : Yes" 
	Carepack = "Yes"
	WarrantyEndDate = split(xmlhttp.responseText,"hpui-normal-row")(2)
	WarrantyEndDate = split(WarrantyEndDate,"</td>")(2)
	WarrantyEndDate = mid(WarrantyEndDate,5)
	WriteLog "Expiration Date is : " & WarrantyEndDate
	
	WarrantyStatus = split(xmlhttp.responseText,"hpui-normal-row")(2)
	WarrantyStatus = split(WarrantyStatus,"color")(1)
	WarrantyStatus = split(WarrantyStatus,">")(1)
	WarrantyStatus = split(WarrantyStatus,"<")(0)
	WriteLog "Warranty Status is : " & WarrantyStatus
Else
	WriteLog "Carepack : No" 
	Carepack = "No"
	WarrantyEndDate = split(xmlhttp.responseText,"hpui-normal-row")(1)
	WarrantyEndDate = split(WarrantyEndDate,"<td>")(3)
	'WarrantyEndDate = replace(replace(WarrantyEndDate,vbcr,""),vblf,"")
	'WarrantyEndDate = split(WarrantyEndDate,"bottomSpaceBig")(1)
	'WarrantyEndDate = split(WarrantyEndDate,">")(1)
	WarrantyEndDay = split(WarrantyEndDate,".")(0)
	'WriteLog "day : " & WarrantyEndDay
	WarrantyEndMonth = split(WarrantyEndDate,".")(1)
	'WriteLog "month : " & WarrantyEndMonth
	WarrantyEndYear = split(WarrantyEndDate,".")(2)
	WarrantyEndYear = split(WarrantyEndYear,"<")(0)
	'WriteLog "year : " & WarrantyEndYear
	WarrantyEndDate = WarrantyEndDay & "." & WarrantyEndMonth & "." & WarrantyEndYear
	WriteLog "Expiration Date is : " & WarrantyEndDate
	
	WarrantyStatus = split(xmlhttp.responseText,"hpui-normal-row")(1)
	'WarrantyStatus = split(WarrantyStatus,"</span></td></tr>")(0)
	'WarrantyStatus = replace(replace(WarrantyStatus,vbcr,""),vblf,"")
	WarrantyStatus = split(WarrantyStatus,"color")(1)
	WarrantyStatus = split(WarrantyStatus,">")(1)
	WarrantyStatus = split(WarrantyStatus,"<")(0)
	WriteLog "Warranty Status is : " & WarrantyStatus
End If
	oReg.SetStringValue HKLM, sKeyPath, "Carepack", CarePack
	oReg.SetStringValue HKLM, sKeyPath, "ExpirationDate", WarrantyEndDate
	oReg.SetStringValue HKLM, sKeyPath, "WarrantyStatus", WarrantyStatus
 End Function
 
 
 Function WriteLog (sText)
    If EnableLogging Then
        oLogfile.WriteLine Now() & "     " & sText
    End If
End Function

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.