Skip to content

Instantly share code, notes, and snippets.

@rafaelfoster
Created November 7, 2014 18:32
Show Gist options
  • Save rafaelfoster/bbbf2148a8680a53c5ae to your computer and use it in GitHub Desktop.
Save rafaelfoster/bbbf2148a8680a53c5ae to your computer and use it in GitHub Desktop.
'=====================================================================
' Dell Warranty Grabber
' Author: Matthew Boyd (iboyd.net)
' Date: 2/14/2012
'
' This is an example of how to query the Dell asset information
' web service for warranty information and parse the XML result.
' values are then written to the registry of the local
' computer. FYI: Sometimes, the web service doesn't return any
' entitlements (warranties), but then returns them after
' subsequent requests.
'
' Usage: cscript.exe DellWarrantyGrabber.vbs
'
' Note: This must be run under an account with admin rights.
' This script is provided AS IS with no support or warranties.
' Use at your own risk!
'=====================================================================
Option Explicit
Dim SoapRequest
Dim url, regkey, svctag
Dim warrantyRows, warrantyCols
Dim objShell, objXML, objWMI, objHTTP, NodeList
Dim i, result
SoapRequest = "<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> <soap:Body> <GetAssetInformation xmlns=""http://support.dell.com/JigsawWebServices/""> <guid>11111111-1111-1111-1111-111111111111</guid> <applicationName>Warranty Information Lookup</applicationName> <serviceTags>!SERVICETAG!</serviceTags> </GetAssetInformation> </soap:Body></soap:Envelope>"
url = "http://xserv.dell.com/jigsawwebservices/AssetService.asmx"
regkey = "HKEY_LOCAL_MACHINE\Software\DellWarrantyInfo"
set objShell = WScript.CreateObject("WScript.Shell")
set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
If InStr(UCase(objWMI.ExecQuery("Select Manufacturer From Win32_ComputerSystem").ItemIndex(0).Manufacturer), "DELL") = 0 then Err.Raise 2, "This is not a Dell dude!", "No Service Tag"
svctag = Trim(objWMI.ExecQuery ("Select SerialNumber from Win32_BIOS").ItemIndex(0).SerialNumber)
wscript.echo "Service Tag: " & svctag
SoapRequest = Replace(SoapRequest, "!SERVICETAG!", svctag)
result = objShell.Run("reg.exe delete '" & regkey & "' /f", true)
If not result = 0 then Err.Raise result, "Unable to delete registry key!", "Code " & result
result = objShell.Run("reg.exe create '" & regkey & "' /ve", true)
If not result = 0 then Err.Raise result, "Unable to delete registry key!", "Code " & result
Set objHTTP = CreateObject("Msxml2.XMLHTTP")
objHTTP.open "POST", URL, false
objHTTP.setRequestHeader "Content-Type", "text/xml"
objHTTP.setRequestHeader "SOAPAction", "http://support.dell.com/JigsawWebServices/GetAssetInformation"
objHTTP.send SoapRequest
result = objHTTP.responseText
Set objXML = CreateObject ("Msxml2.DOMDocument")
objXML.LoadXml result
If not objXML.SelectSinglenode ("//faultstring") is nothing then
Err.Raise 1, "Error:" & objXML.SelectSingleNode("//faultcode").text, Trim(objXML.SelectSingleNode("//faultstring").text)
End If
wscript.echo objXML.xml
Set NodeList = objXML.SelectNodes("//Asset/Entitlements/EntitlementData")
wscript.echo NodeList.length & " results returned: "
For i = 0 to NodeList.length - 1
set warrantyCols = NodeList.item(i)
wscript.echo Mid(warrantyCols.SelectSingleNode("ServiceLevelDescription").text,4)
objShell.regWrite regkey & "\" & i & "\", ""
objShell.regWrite regkey & "\" & i & "\Description", Mid(warrantyCols.SelectSingleNode("ServiceLevelDescription").text, 4)
objShell.regWrite regkey & "\" & i & "\Provider", warrantyCols.SelectSingleNode("Provider").text
objShell.regWrite regkey & "\" & i & "\Entitlement Type", warrantyCols.SelectSingleNode("EntitlementType").text
objShell.regWrite regkey & "\" & i & "\Start Date", Left(warrantyCols.SelectSingleNode("StartDate").text, 10)
objShell.regWrite regkey & "\" & i & "\End Date", Left(warrantyCols.SelectSingleNode("EndDate").text, 10)
objShell.regWrite regkey & "\" & i & "\Days Left", warrantyCols.SelectSingleNode("DaysLeft").text
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment