![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBscript Help Hi all, I've been racking my brain trying to figure out what is wrong with this. The script runs and fails at line 60 (For Each objPatch in ColPatches). Any help would be appreciatd. Thanks in advance. 'On Error Resume Next strKB = Inputbox ("Enter the KB Number") ' in KB917537 format x = 2 'Create an Excel Work Sheet Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True objExcel.Workbooks.Add objExcel.Cells(1, 1).Value = "Machine Name" objExcel.Cells(1, 2).Value = "KB" objExcel.Cells(1, 3).Value = "Installed On" objExcel.Cells(1, 4).Value = "Report Time Stamp" objExcel.Range("A1:G1").Select objExcel.Selection.Interior.ColorIndex = 19 objExcel.Selection.Font.ColorIndex = 11 objExcel.Selection.Font.Bold = True objExcel.Cells.EntireColumn.AutoFit 'Read machine names from a txt file Set Fso = CreateObject("Scripting.FileSystemObject") Set InputFile = fso.OpenTextFile("MachineList.Txt") Do While Not (InputFile.atEndOfStream) strComputer = InputFile.ReadLine intRow = x objExcel.Cells(intRow, 1).Value = strComputer GetPatchInfo objExcel.Cells(intRow, 4).Value = Now() x = x + 1 Loop Wscript.Echo "Done" '********************************************************************************************************* 'Get patch Status from WMI Sub GetPatchInfo Set objWMIService = GetObject("winmgmts:" & _ "{impersonationLevel=Impersonate}!\\" & strComputer & "\root \cimv2") Set colPatches = objWMIService.ExecQuery _ ("Select * From Win32_QuickFixEngineering Where HotFixID = ‘”& strKB”’'") objExcel.Cells(intRow, 2).Value = objPatch.Description objExcel.Cells(intRow, 3).Value = objPatch.InstalledOn Next End Sub |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBscript Help <gazamon@xxxxxx> wrote in message news:8255ab1f-fc41-4a92-ba04-43d0f57e53ff@xxxxxx Quote: > Hi all, > I've been racking my brain trying to figure out what is wrong with > this. The script runs and fails at line 60 (For Each objPatch in > ColPatches). Any help would be appreciatd. Thanks in advance. > [...] > Set colPatches = objWMIService.ExecQuery _ > ("Select * From Win32_QuickFixEngineering Where HotFixID = ‘”& >strKB”’'") and double quotes in the HotFixID area above have high ascii values. It looks like Word of other editor has done some auto-formatting for you. Try chaning the line to: Set colPatches = objWMIService.ExecQuery _ ("Select * From Win32_QuickFixEngineering " _ & "Where HotFixID = '" & strKB & "'") Also, just below that line, insert: For Each objPatch in colPatches I ran it with these changes on my WinXP Pro SP2 computer and it works. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBscript Help On Oct 25, 1:07*pm, "James Whitlow" <jwhitlow.60372...@xxxxxx> wrote: Quote: > <gaza...@xxxxxx> wrote in message > > news:8255ab1f-fc41-4a92-ba04-43d0f57e53ff@xxxxxx > Quote: > > Hi all, > > I've been racking my brain trying to figure out what is wrong with > > this. The script runs and fails at line 60 (For Each objPatch in > > ColPatches). Any help would be appreciatd. Thanks in advance. > > [...] > > *Set colPatches = objWMIService.ExecQuery _ > > * *("Select * From Win32_QuickFixEngineering Where HotFixID = ‘”& > >strKB”’'") > * I think it is a problem with your quotes & a missing 'For'. Your single > and double quotes in the HotFixID area above have high ascii values. It > looks like Word of other editor has done some auto-formatting for you. Try > chaning the line to: > > *Set colPatches = objWMIService.ExecQuery _ > * ("Select * From Win32_QuickFixEngineering " _ > * & "Where HotFixID = '" & strKB & "'") > > * Also, just below that line, insert: > > For Each objPatch in colPatches > > * I ran it with these changes on my WinXP Pro SP2 computer and it works.. |
My System Specs![]() |
| | #4 (permalink) |
| Vista | Re: VBscript Help Hello all. In using this VBS, it works great until it finds a computer not on the network and it errors out. Is there a way to add a line to skip the error and continue with the server list? Thanks |
My System Specs![]() |
| | #5 (permalink) |
| | Re: VBscript Help On Dec 10, 12:06*pm, hgiljr <gu...@xxxxxx-email.com> wrote: Quote: > Hello all. *In using this VBS, it works great until it finds a computer > not on the network and it errors out. Is there a way to add a line to > skip the error and continue with the server list? *Thanks > > -- > hgiljr error trapping around the sensitive code and then have your procedure handle the error, something like this ... ' in the sub ... Sub GetPatchInfo on error resume next Set objWMIService = GetObject("winmgmts:" & _ "{impersonationLevel=Impersonate}!\\" & strComputer _ & "\root\cimv2") if err.number <> 0 then exit sub on error resume next ' the rest of the code ... The other approach is to 'ping' the computer and proceed only if it's on line. Here is a version of such a procedure that works in all WSH equipped environments ... Function IsConnectible(sHost, iPings, iTO) ' Returns True or False based on the output from ping.exe ' ' Authors: Alex Angelopoulos/Torgeir Bakken ' Modified by: Tom Lavedas ' Works an "all" WSH versions ' sHost is a hostname or IP ' iPings is number of ping attempts ' iTO is timeout in milliseconds ' if values are set to "", then defaults below used Dim nRes If iPings = "" Then iPings = 1 ' default number of pings If iTO = "" Then iTO = 250 ' default timeout per ping with CreateObject("WScript.Shell") nRes = .Run("%comspec% /c ping.exe -n " & iPings & " -w " & iTO _ & " " & sHost & " | find ""TTL="" > nul 2>&1", 0, True) end with IsConnectible = (nRes = 0) End Function it would be used in the Do Loop something like ... if IsConnectible(strComputer, 1, 500) then GetPatchInfo HTH. BTW, it might be more productive to formulate your question as a new post, since people may not go to the end of an old thread like this one to find you new post. It all depends on the reader setup they're using whether they'll even see it. Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #6 (permalink) |
| | Re: VBscript Help Tom Lavedas schrieb: Quote: > On Dec 10, 12:06 pm, hgiljr <gu...@xxxxxx-email.com> wrote: Quote: >> Hello all. In using this VBS, it works great until it finds a computer >> not on the network and it errors out. Is there a way to add a line to >> skip the error and continue with the server list? Thanks Quote: > There are a couple of ways. The most direct method is to turn off > error trapping around the sensitive code and then have your procedure > handle the error, something like this ... > > ' in the sub ... > Sub GetPatchInfo > > on error resume next > Set objWMIService = GetObject("winmgmts:" & _ > "{impersonationLevel=Impersonate}!\\" & strComputer _ > & "\root\cimv2") > if err.number <> 0 then exit sub > on error resume next On Error GoTo 0 Quote: > ' the rest of the code ... |
My System Specs![]() |
| | #7 (permalink) |
| | Re: VBscript Help On Dec 10, 1:15*pm, "ekkehard.horner" <ekkehard.hor...@xxxxxx> wrote: Quote: > Tom Lavedas schrieb: > Quote: > > On Dec 10, 12:06 pm, hgiljr <gu...@xxxxxx-email.com> wrote: Quote: > >> Hello all. *In using this VBS, it works great until it finds a computer > >> not on the network and it errors out. Is there a way to add a line to > >> skip the error and continue with the server list? *Thanks Quote: > > There are a couple of ways. *The most direct method is to turn off > > error trapping around the sensitive code and then have your procedure > > handle the error, something like this ... Quote: > > ' in the sub ... > > Sub GetPatchInfo Quote: > > on error resume next > > * Set objWMIService = GetObject("winmgmts:" & _ > > * * *"{impersonationLevel=Impersonate}!\\" & strComputer _ > > * * *& "\root\cimv2") > > * if err.number <> 0 then exit sub > > on error resume next > ==> > * *On Error GoTo 0> ' the rest of the code ... > > [...] Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #8 (permalink) |
| Vista | Re: VBscript Help Worked. thanks agian |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| New to VBscript, Help please! | VB Script | |||
| CSS and VBscript | VB Script | |||
| Where is VBscript now? | VB Script | |||
| How to do No hang up VBScript (nohup for VBScript) | VB Script | |||
| vbscript and HTA help | VB Script | |||