Advertisement
Guest User

Dell Digital Delivery Key Return Utility

a guest
Dec 6th, 2013
2,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.26 KB | None | 0 0
  1. ; DellDigitalDeliveryCheck.au3/.exe
  2. ; Created: 12/5/2013
  3. ; Purpose: Collects required system information and
  4. ;           submits it to the Dell Digital Delivery
  5. ;           service in order to get the products and
  6. ;           keys that belong to this computer.
  7. ; Required library: WinHTTP (Tested with 1.6.3.4)
  8. ;           http://code.google.com/p/autoit-winhttp/downloads/list
  9. ;
  10. ; NOTE: This is day-old code that I _just_ finished writing. It's not very
  11. ;   polished, but does what I need it to do.
  12. #include <Date.au3>
  13. #include "WinHTTP.au3"
  14.  
  15. ; Query WMI for Win32_ComputerSystemProduct and Win32_Baseboard
  16. $sWMIService = "winmgmts:\\" & @ComputerName & "\root\CIMV2"
  17. $objWMIService = ObjGet($sWMIService)
  18. If IsObj($objWMIService) Then
  19.     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard")
  20.     If IsObj($colItems) Then
  21.         For $oItem In $colItems
  22.             $sBBProduct = $oItem.Product
  23.             $sBBSerialNum = $oItem.SerialNumber
  24.         Next
  25.     EndIf
  26.  
  27.     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")
  28.     If IsObj($colItems) Then
  29.         For $oItem IN $colItems
  30.             $sCSPSerialNum = $oItem.IdentifyingNumber
  31.             $sCSPModel = $oItem.Name
  32.             $sCSPVendor = $oItem.Vendor
  33.             $sCSPVersion = $oItem.Version
  34.         Next
  35.     EndIf
  36.  
  37.     $objWmiService = ""
  38.     $colItems = ""
  39.     $oItem = ""
  40. Else
  41.     MsgBox(0, "DDD Check", "Failed to query WMI.")
  42.     exit
  43. EndIf
  44.  
  45. ; Ask which serial number to use
  46. $sInpSerialNumber = InputBox("DDD Check", "Enter serial number to check against", $sCSPSerialNum)
  47. if $sInpSerialNumber <> "" Then
  48.     ; Just use our local serial number if the input is bad
  49.     $sCSPSerialNum = $sInpSerialNumber
  50. EndIf
  51.  
  52. ; Put together and submit our request
  53. $tDateTime = _Date_Time_GetSystemTime()
  54. $sDateTime = _Date_Time_SystemTimeToDateTimeStr($tDateTime, 1)
  55. ; A note on this: The commented-out line will format the header the same way that the official utility does (save for the date - The official utility uses 12 hour time with a space and then 'AM or 'PM' - This code uses 24 hour time because I was lazy and it works fine regardless.)
  56. ; I've found that their system doesn't really care much about this, just so long as it's there.
  57. ;$sSTPLine = $sDateTime & "|" & "DELL1" & "|" & $sCSPSerialNum & "|" & $sCSPVendor & "|" & $sCSPModel & "|" & $sBBSerialNum & "|" & $sBBProduct
  58. $sSTPLine = $sDateTime & "|DELL1|" & $sCSPSerialNum & "|DELL INC.|COMPUTER MODEL|/" & $sCSPSerialNum & "/CN000000000000/|0X010C"
  59.  
  60. $sHeaders  = "Content-Type: application/xml; charset=utf-8" & @CRLF
  61. $sHeaders &= "X-Dell-STP: " & $sSTPLine & @CRLF
  62. $sHeaders &= "X-Dell-CirrusClientVersion: 2.8.1000.0" & @CRLF
  63. ; This 'Autorization' header is just the username and password (see below) encoded using Base64.
  64. $sHeaders &= "Authorization: Basic U2VydmljZUNpcnJ1czpDaXJydXNAZGVsbA==" & @CRLF
  65.  
  66. $sUserName = "ServiceCirrus"
  67. $sPassword = "Cirrus@dell"
  68. $sDomain = "cloud.dell.com"
  69. $sPage = "DEEServices/DEE.svc/v1/GetEntitlements?AId=" & $sCSPSerialNum
  70.  
  71. ; Initialize and get session handle
  72. $hOpen = _WinHttpOpen()
  73.  
  74. ; Get connection handle
  75. $hConnect = _WinHttpConnect($hOpen, $sDomain)
  76.  
  77. ; Make a request
  78. $hRequest = _WinHttpOpenRequest($hConnect, "GET", $sPage, -1, -1, -1, $WINHTTP_FLAG_SECURE)
  79.  
  80. ; Send it. Specify additional data to send too.
  81. _WinHttpSendRequest($hRequest, $sHeaders)
  82.  
  83. ; Wait for the response
  84. _WinHttpReceiveResponse($hRequest)
  85.  
  86. ; See what's returned
  87. $sReturned = ""
  88. If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
  89.     Do
  90.         $sReturned &= _WinHttpReadData($hRequest)
  91.     Until @error
  92. EndIf
  93.  
  94. ; Close handles
  95. _WinHttpCloseHandle($hRequest)
  96. _WinHttpCloseHandle($hConnect)
  97. _WinHttpCloseHandle($hOpen)
  98.  
  99. ; See what's returned
  100. $bFoundAcrobat = FALSE
  101. $aEntitlements = XMLParseSimple($sReturned, "EntitlementDTO")
  102. if @error Then
  103.     Dim $aEntitlements[1]
  104. EndIf
  105. For $sEntitlement in $aEntitlements
  106.     $sEntitlementName = XMLParseSimple($sEntitlement, "Name", '', '', 0)
  107.     if StringinStr($sEntitlementName, "Adobe Acrobat XI") > 0 Then
  108.         $sProductKey = XMLParseSimple($sEntitlement, "Key", '', '', 0)
  109.         ClipPut($sProductKey)
  110.         MsgBox(0, "DDD Check", $sProductKey & @CRLF & @CRLF & "Key is on clipboard")
  111.         $bFoundAcrobat = TRUE
  112.     EndIf
  113. Next
  114.  
  115. if not $bFoundAcrobat Then
  116.     MsgBox(0, "DDD Check", "Did not find Adobe Acrobat XI in returned XML.")
  117.     ClipPut($sReturned)
  118.     MsgBox(0, "DDD Check - Raw Return", $sReturned)
  119. EndIf
  120.  
  121. ; Function Name: XMLParseSimple
  122. ; Function Description: function to get the content of a xml-tag
  123. ; Function Author: ChristophX86
  124. Func XMLParseSimple($XML, $Tag, $Attribute='', $Parent='', $Flag=1)
  125.     Local $Pattern = '<' & $Tag & '(?:.+?)' & $Attribute & '="(.*?)"(?:.*?)>'
  126.     If ($Attribute = '') Then
  127.         $Pattern = '<' & $Tag & '(?:.*?)>(.*?)</' & $Tag & '>'
  128.     EndIf
  129.     If ($Parent <> '') Then
  130.         $Pattern = '<' & $Parent & '(?:.*?)>(?:.*?)' & $Pattern & '(?:.*?)</' & $Parent & '>'
  131.     EndIf
  132.     If ($Flag = -1) Then ; return boolean
  133.         Return StringRegExp($XML, '(?s)' & $Pattern, 0)
  134.     EndIf
  135.     Local $SRE = StringRegExp($XML, '(?s)' & $Pattern, 3)
  136.     If @error Then
  137.         SetError(1)
  138.         Return ''
  139.     Else
  140.         Switch $Flag
  141.             Case 0 ; return only first match
  142.                 If (UBound($SRE, 1) >= 1) Then
  143.                     Return $SRE[0]
  144.                 Else
  145.                     SetError(10)
  146.                     Return $SRE
  147.                 EndIf
  148.             Case 1 ; return the complete array
  149.                 Return $SRE
  150.             Case Else
  151.                 SetError(2)
  152.                 Return $SRE
  153.         EndSwitch
  154.     EndIf
  155. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement