.

sexta-feira, 17 de setembro de 2010

Warranty Dell Code VBS - Garantia Dell Script

Como posso trazer informacoes sobre garantia do site da dell de uma lista de service tag?

Com o codigo abaixo e um arquivo de texto com o service tag de servidores e computadores Dell é possivel trazer as informaçoes de data de garantia, data de compra, local de compra, e mais informacões importantes, como o arquivo de saida é um CSV é possivel fazer a importação para um banco de dados.

Codigo abaixo:

'******************************************************
'* Author: Unknown / Thiago Cardoso 
'* Version: 1.0
'* last modified: 09/16/2010
'* This script will check the Dell website the warranty  of computer service tag.
'* Input File := ServiceTagsDell.txt (separated by enter)
'* Example:
'* J1JO45X
'* ASA465J
'* Output File:Result.csv (comma separated values "value","value",)
'* Example:"value","value","value"
'* Cscript WarrantyDell.vbs
'******************************************************

Set dtmConvertedDate = Createobject("WbemScripting.SWbemDateTime")
strComputer = "."
'Files I/O
strInputFile = "ServiceTagsDell.txt"
strOutputFile = "Result.csv"
arrHeads = Array("Service Tag:", "Days Left")
Set oFSO = Createobject("Scripting.FileSystemobject")
Const intForRead = 1
Set oHTTP = Createobject("Msxml2.XMLHTTP")
strDetails = """Service Tag"",""System Type"",""Ship Date"",""Dell IBU"",""Description"",""Provider"",""Start Date"",""End Date"",""Days Left"""
If oFSO.FileExists(strInputFile) Then
 Set oInputFile = oFSO.OpenTextFile(strInputFile, intForRead, False)
 While Not oInputFile.AtEndOfStream
    strServiceTag = oInputFile.ReadLine
    strCurrentTag = ""
    'Dell Website
    strURL = "http://supportapj.dell.com/support/topics/topic.aspx/ap/shared/support/my_systems_info/en/details?c=in&cs=inbsd1&l=en&s=bsd&ServiceTag=" & strServiceTag & "&~tab=1"
    oHTTP.open "GET", strURL, False
    oHTTP.send
    strPgText = oHTTP.responseText
    For Each strHead In arrHeads
    intSummaryPos = InStr(LCase(strPgText), LCase(strHead))
    If intSummaryPos > 0 Then
       intSmmTblStart = InStrRev(LCase(strPgText), "<table", intSummaryPos)
       intSmmTblEnd = InStr(intSummaryPos, LCase(strPgText), "</table>") + 8
       strInfoTbl = Mid(strPgText, intSmmTblStart, intSmmTblEnd - intSmmTblStart)
       strInfoTbl = Replace(Replace(Replace(strInfoTbl, VbCrLf, ""), vbCr, ""), vbLf, "")
       arrCells = Split(LCase(strInfoTbl), "</td>")
       For intCell = LBound(arrCells) To UBound(arrCells)
       arrCells(intCell) = Trim(arrCells(intCell))
       intOpenTag = InStr(arrCells(intCell), "<")
       While intOpenTag > 0
          intCloseTag = InStr(intOpenTag, arrCells(intCell), ">") + 1
          strNewCell = ""
          If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Left(arrCells(intCell), intOpenTag - 1))
          If intCloseTag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intCloseTag))
          arrCells(intCell) = Replace(Trim(strNewCell), " &nbsp;&nbsp;&nbsp;&nbsp;change service tag","")
          intOpenTag = InStr(arrCells(intCell), "<")   
       Wend
       Next
       If LCase(arrCells(0)) = LCase("Service Tag:") Then
       strCurrentTag = ""
        For intField = 1 To UBound(arrCells) Step 2
           If strCurrentTag = "" Then
           strCurrentTag = """" & arrCells(intField) & """"
           Else
           strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
           End If
        Next
       ElseIf LCase(arrCells(0)) = LCase("Description") Then
       If  UBound(arrCells) < 10 then 
        For intField = 5 To UBound(arrCells)
           strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
        Next    
       Else
        For intField = 5 To 9
           strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
        Next
       End If 
       End If
    Else
       strCurrentTag = """" & strServiceTag & """,""No warranty information found."""
    End If
    Next
    strDetails = strDetails & VbCrLf & strCurrentTag
 Wend
 oInputFile.Close
 Set oInputFile = Nothing
 Set oOutputFile = oFSO.CreateTextFile(strOutputFile, True)
 oOutputFile.Write strDetails
 oOutputFile.Close
 Set oOutputFile = Nothing
 Set oFSO = Nothing
Else
 MsgBox "The file does not exists " & strInputFile & ". Create please."
End If

Um comentário:

Edson Soares disse...

Caraca! que massa Thiago!
isso vai ser uma mão na roda para levantar e consultar dados dos computadores do parque =]

Parabéns e valeu pela dica

vamos aos testes... hehe