'=========================
' Get_Warranty_Info_On_HP_Equipment_From_Service_Tag.vbs
' http://www.experts-exchange.com/Programming/Languages/Q_23097377.html
strInputFile = "HPSerialNumbers.txt"
strOutputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Results.csv"
arrTextToSearchFor = Array("Warranty Type","HWM Onsite")
arrJoinFields = Array("Serial Number","Product Number","Product Description","Date of Warranty Check","Warranty Type","Start Date","HP Care Pack Serial Number","HWM Onsite","Status","End Date","Service Level","Deliverables","6-Hour, 24x7, Call-To-Repair, HW Support","Wty: HP HW Maintenance Onsite Support","Wty: HP Support for Initial Setup")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strDetails = """WARRANTY INFORMATION"""
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
arrLine = Split(objInputFile.ReadLine, ";")
strProductNumber = arrLine(0)
strSerialNumber = arrLine(1)
strURL = "http://www11.itrc.hp.com/service/ewarranty/warrantyResults.do?BODServiceID=NA&serialNumber10=&RegisteredPurchaseDate=&y=11&x=26&serialNumber4=&country=IN&serialNumber9=&serialNumber5=&serialNumber6=&serialNumber7=&serialNumber8=&serialNumber1=" & strSerialNumber & "&serialNumber2=&serialNumber3=&productNumber=" & strProductNumber & "&hpweb_printable=true"
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate strURL
While objIE.ReadyState <> 4
WScript.Sleep 100
Wend
strPageText = objIE.Document.Body.InnerHTML
'WScript.Echo strPageText
' Reset the text for the current product
strCurrentProduct = ""
For Each strSearchText In arrTextToSearchFor
intSummaryPos = InStr(LCase(strPageText), LCase(strSearchText))
If intSummaryPos > 0 Then
intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
strInfoTable = Replace(Replace(Replace(strInfoTable, VbCrLf, ""), vbCr, ""), vbLf, "")
strInfoTable = Replace(strInfoTable, "<BR>", VbLf)
'WScript.Echo strInfoTable
arrCells = Split(LCase(strInfoTable), "</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) = Trim(strNewCell)
intOpenTag = InStr(arrCells(intCell), "<")
Wend
Next
'WScript.Echo Join(arrCells, "|")
strCurrentProduct = strCurrentProduct & Join(arrCells, "|")
strCurrentProduct = Replace(strCurrentProduct, "||", "|")
'strCurrentProduct = Replace(Replace(Replace(strCurrentProduct, "||", "|"), VbCrLf & "|", "|"), "|" & VbCrLf, "|")
If Left(strCurrentProduct, 1) = "|" Then strCurrentProduct = Right(strCurrentProduct, Len(strCurrentProduct) - 1)
If Right(strCurrentProduct, 1) = "|" Then strCurrentProduct = Left(strCurrentProduct, Len(strCurrentProduct) - 1)
If LCase(arrCells(0)) = LCase("Service Tag:") Then
'strCurrentTag = """" & strServiceTag & """"
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
For intField = 5 To UBound(arrCells)
strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
Next
End If
Else
strCurrentTag = """" & strServiceTag & """,""No warranty information found."""
End If
Next
'WScript.Echo strCurrentProduct
If InStr(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number") > 0 Then _
strCurrentProduct = Replace(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number", "hp care pack serial number")
arrCells = Split(strCurrentProduct, "|")
strJoinFields = ";" & Join(arrJoinFields, ";") & ";"
For Each strCell In arrCells
strCell = ProperCase_Words(strCell)
If InStr(LCase(strJoinFields), ";" & LCase(strCell) & ";") > 0 Then
strDetails = strDetails & VbCrLf & """" & strCell & """"
Else
'strDetails = Left(strDetails, Len(strDetails) - 1) & ": " & strCell & """"
strDetails = Left(strDetails, Len(strDetails) - 1) & """,""" & strCell & """"
End If
Next
strDetails = strDetails & VbCrLf & VbCrLf & "==========================" & VbCrLf
objIE.Quit
Wend
objInputFile.Close
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing
Set objShell = CreateObject("WScript.Shell")
objShell.Run """" & strOutputFile & """", 1, False
'MsgBox "Done. Please see " & strOutputFile
Function ProperCase_Words(strText)
If IsNumeric(Left(strText, 1)) = False Then
strText = UCase(Left(strText, 1)) & Mid(strText, 2)
End If
intPos = InStr(strText, " ")
Do
If IsNumeric(Mid(strText, intPos + 1, 1)) = False Then
strText = Left(strText, intPos) & UCase(Mid(strText, intPos + 1, 1)) & Mid(strText, intPos + 2)
End If
intPos = InStr(intPos + 1, strText, " ")
If intPos > Len(strText) - 1 Then Exit Do
Loop While intPos > 0
ProperCase_Words = strText
End Function
'=========================
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
by: TheLearnedOnePosted on 2009-10-14 at 05:15:49ID: 25569578
It might be easier if you explained what this code does (and what your question is), since E-E is usually about answering questions, and not a free-coder system.