Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Script to See If URL is Accessable

I have a windows 7 workstation and looking for a way to check the status of a URL's on our network to see if they are still valid.  I am trying to do a lot of cleanup work.

 I would like to reference a CSV file and have he script check/ping each URL and write the status to a Text file.

Example

URL \\ServerA\Share  -> No Reachable
URL \\ServerB\Share -> Reachable
0
compdigit44
Asked:
compdigit44
  • 46
  • 29
  • 7
1 Solution
 
vb_elmarCommented:
Set oFS = CreateObject("Scripting.FileSystemObject")
Set outFile = oFS.CreateTextFile("c:\sample.txt")
    outFile.WriteLine "\\ServerA\Share" & ";" & URLExists("http://ServerA.com/Share") & ";"
    outFile.WriteLine "\\ServerB\Share" & ";" & URLExists("http://ServerB.com/Share") & ";"
    outFile.WriteLine "\\ServerC\Share" & ";" & URLExists("http://ServerC.com/Share") & ";"
outFile.Close

Function URLExists(strURL)
    Dim o, Retval, isNumber404
    On Error Resume Next
    Set o = CreateObject("Microsoft.XMLHTTP")
    o.open "GET", strURL, False
    o.send
    If Err.Number = 0 Then
        Retval = o.responseText
        isNumber404 = Left(Retval, 1)
        If Asc(isNumber404) > 47 And Asc(isNumber404) < 58 Then 'chars 0-9
            URLExists = "No Reachable" ' HTTP Error code returned
        Else
            URLExists = "Reachable"
        End If
    Else
        URLExists = "No network or URL misspelled."
        Err.Clear
    End If
    Set o = Nothing
End Function

Open in new window

0
 
Joseph DalyCommented:
Powershell is hugely easier for this task.

test-path \\server\share

If its reachable it returns true if not it returns false.

import-csv c:\filename.csv | foreach {
$exists = test-path $_.pathname
$path = $_.pathname
"$path, $exists" >> C:\file.txt
}

This will outut something like

\\server\share, true
\\server\share, false
0
 
compdigit44Author Commented:
I will give this a try tomorrow and let you know how I make out..

Thanks Again.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Joseph DalyCommented:
One thing to note with that powershell. The $_. denotes whatever your column heading in the csv file is.  The file must have a heading and then the values in a column underneath that.
0
 
compdigit44Author Commented:
I setup my CSV so it used one column with Cell one with a heading of Printers and all URL underneath it..

I get the error "Cannot bind argument to parameter 'path' is NULL
0
 
Joseph DalyCommented:
Can you post the csv?
0
 
compdigit44Author Commented:
I cannot post the CSV since it contains sensitive information

But it looks like the following in CSV format all using one column. Starting are column and row one .

\\ServerA\Share1
\\ShareA\Share2

Here is the exact error I am seeing....

Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\PrinterURLChecker.ps1:2 char:21
+ $exists = test-path $_.pathname
0
 
Joseph DalyCommented:
You don't have a heading listed.
0
 
compdigit44Author Commented:
Stupid question... What do you mean by heading... Column heading...?
0
 
Joseph DalyCommented:
Like this.
filename.csv
0
 
compdigit44Author Commented:
I tried adding a name to column one row one and got the same message
0
 
Joseph DalyCommented:
The name in the column has to match the name in the script.
0
 
compdigit44Author Commented:
Where do I put the column name in the script... sorry
0
 
Joseph DalyCommented:
The $_. References the name of heading for the column
0
 
compdigit44Author Commented:
Thanks I was able to get it to run and learned something about test-path... One problem though.. the out-put file list are shares are false which i know is not true since they exist....
0
 
compdigit44Author Commented:
I think I found the problem... The URL I need to check have spaces. In CSV which is large how can I added quotes to all items easily.. I found how to add quotes to a columns using a custom format ..  I will keep you posted.
0
 
compdigit44Author Commented:
Still not working and showing everything as False...

Here is the custom format I used to place quote around everything...

https://answers.yahoo.com/question/index?qid=20100210103758AAsTyfK

Custom format - "''"@"''"
that is quote,2 apostrophes, quote,@, quote, 2 apostrophes, quote
Apply to column.
0
 
compdigit44Author Commented:
tried typing in test-path \\server\share of a working URL and it came up false.
0
 
compdigit44Author Commented:
vb_elmar I looked at your script but do not see where the script references as source CSV file
0
 
vb_elmarCommented:
The following .vbs code reads the "filename.csf" starting from the second line and tells you each server status with a messagebox.
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Do While Not inputFile.AtEndOfStream
    L2 = inputFile.ReadLine
    If L2 <> "Pathname" Then
        WScript.Echo URLExists(L2)
    End If
Loop
inputFile.Close

Function URLExists(strURL)
    Dim o, Retval, isNumber404
    On Error Resume Next
    Set o = CreateObject("Microsoft.XMLHTTP")
    o.open "GET", strURL, False
    o.send
    If Err.Number = 0 Then
        Retval = o.responseText
        isNumber404 = Left(Retval, 1)
        If Asc(isNumber404) > 47 And Asc(isNumber404) < 58 Then 'chars 0-9
            URLExists = "No Reachable" ' HTTP Error code returned
        Else
            URLExists = "Reachable"
        End If
    Else
        URLExists = "No network or URL misspelled."
        Err.Clear
    End If
    Set o = Nothing
End Function

Open in new window

0
 
compdigit44Author Commented:
I get the error No error URL misspelled... My URL have spaces and I made sure to place quotes around them I am not sure if this causing the problem...
0
 
compdigit44Author Commented:
Any way to just dump the results to file and not dialog box since I have a large csv file..
0
 
vb_elmarCommented:
This is how to write results to file:
Set outFile = fso.CreateTextFile("c:\sample.txt")
    outFile.WriteLine URLExists(L2)
outFile.Close

Open in new window

0
 
compdigit44Author Commented:
Thanks any thought on my my CSV isn't working...
I am sure it has to so with the spaces and qutoes
0
 
vb_elmarCommented:
A working URL never contains quotes. To remove quotes from your CSV file replace the term ...
L2 = inputFile.ReadLine
If L2 <> "Pathname" Then

Open in new window

by the term ...
L2 = inputFile.ReadLine
L2 = Replace(L2, Chr(34), "") 'replacing quotes
If L2 <> "Pathname" Then

Open in new window

0
 
compdigit44Author Commented:
OK..

This may be the problem while the powershell script is not returning the proper values as well..

So my CSV should not contain quotes for example.. some of my urls look like this:

\\ServerA\Some Share Name

I am not a scripting person so I am trying to understand what you need me to do here..

Sorry if this is an obvious question/answer
0
 
vb_elmarCommented:
To check an 'UNC path' like ...
\\ServerA\Some Share Name
... try this:
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L2 = inputFile.ReadLine
    L2 = Replace(L2, Chr(34), "") 'remove all quotes "
    L2 = Replace(L2, ";", "")     'remove semicolons ;
    If L2 <> "Pathname" Then
    outFile.WriteLine L2 & ";" & fso.FolderExists(L2)
    End If
Loop
inputFile.Close
outFile.Close

Open in new window

0
 
compdigit44Author Commented:
I will try it when I able back at the office tomorrow...

Thanks Again for the help everyone
0
 
compdigit44Author Commented:
The script runs perfect BUT everything but all URL's come up as false. An I know the one'e listed are LIVE URL's..

I really think it has something to do with the fact there are spaces in the same.
0
 
vb_elmarCommented:
The script from 2014-10-12 at 02:33:37 is designed for an 'UNC path' like ...
\\ServerA\Some Share Name
and it allows to process spaces.

-But it is not designed to process URL's containing colons like
e.g. http://

Please note that opening an URL requires another
method than opening an 'UNC path'.
0
 
compdigit44Author Commented:
Yes this is the script i am using and I am using UNC path's not URL's sorry ..

All UNC path return as FALSE which is not true because they are known good working URL's
0
 
vb_elmarCommented:
I modifierd the code. It shows the  'UNC path' in a MsgBox before processing it. Is the 'UNC path' in the MsgBox correct?
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L2 = inputFile.ReadLine
    L2 = Replace(L2, Chr(34), "") 'remove all quotes "
    L2 = Replace(L2, ";", "")     'remove semicolons ;
    If L2 <> "Pathname" Then
    WScript.Echo "->" & L2 & "<-"
    outFile.WriteLine L2 & ";" & fso.FolderExists(L2)
    End If
Loop
inputFile.Close
outFile.Close

Open in new window

0
 
compdigit44Author Commented:
The message box list all share names correctly...
0
 
vb_elmarCommented:
Try to replace
fso.FolderExists(L2)
by
(fso.FolderExists(L2))
0
 
compdigit44Author Commented:
All UNC paths still return as false....
0
 
vb_elmarCommented:
I modified the MsgBox again. Does the MsgBox show all 'UNC paths' false?
Dim L22, isOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Split(L22, ";")(0)
    If L22 <> "Pathname" Then
      isOnline = (fso.FolderExists(L22))
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isOnline
      outFile.WriteLine L22 & ";" & isOnline
    End If
Loop
inputFile.Close
outFile.Close

Open in new window

0
 
compdigit44Author Commented:
Yes all UNC path name so as false in the MSG Box.
0
 
vb_elmarCommented:
When I run the code from 2014-10-13 at 17:21:30 it shows a MsgBox:
In the 1st line I see the 'UNC path' and
in the 2nd line the MsgBox shows True
ee.gif
0
 
compdigit44Author Commented:
Thank you for sticking with me on this. WIth 500 UNC path's to check I am hoping to get this. script to work.

I am still not having any luck. I copied and pasted all UNC paths from my Excel 2010 spreadsheet into a new clean CSV file and got the same result..

Yet when I take the same UNC path in go to start -> run the path bring me to the correct network location.

I even tried switching to lower case and it did not work
0
 
compdigit44Author Commented:
I do not understand why this will not work with powershell or VBS... I have upload a sample of what my UNC path's look like..
Sample-UNC.csv
0
 
vb_elmarCommented:
I think line 1 should better be written as it is shown in line 2
because (as far I know) leading spaces are not allowed.
\\Server-1A1\ HP LaserJet 4050 H4
\\Server-1A1\HP LaserJet 4050 H4

Open in new window

0
 
vb_elmarCommented:
I modified the code to prevent leading spaces.
Dim L22, isOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0)
    If L22 <> "Pathname" Then
      isOnline = (fso.FolderExists(L22))
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isOnline
      outFile.WriteLine L22 & ";" & isOnline
    End If
Loop
inputFile.Close
outFile.Close

Open in new window

0
 
vb_elmarCommented:
Here is a function to check if a printer is online:
WScript.Echo isPrinterOnline("\\Server-1A1\HP LaserJet 4050 H4")

Function isPrinterOnline(L77)
Dim o
Dim oWMI
Dim allPrinters
Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer where Default = 'True'")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "Printer Idle"
    Case 4
        isPrinterOnline = "Printer Printing"
    Case 5
        isPrinterOnline = "Printer WarmingUp"
    Case Else
        isPrinterOnline = "Printer OffLine"
    End Select
Next
End Function

Open in new window

0
 
compdigit44Author Commented:
I will try this tomorrow.. could this script read a CSV file??
0
 
vb_elmarCommented:
The following sample reads the first column of a .csv file with the printer 'UNC path' information and checks if printer is online:
Dim L22, isDeviceOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0) 'read first col of a .csv file
    If L22 <> "Pathname" Then
      isDeviceOnline = isPrinterOnline(L22)
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isDeviceOnline      
      outFile.WriteLine L22 & ";" & isDeviceOnline
    End If
Loop
inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Dim o, oWMI, allPrinters
Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer where Default = 'True'")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
End Function

Open in new window

0
 
compdigit44Author Commented:
Thanks but I am getting the following script error

Line: 21
Char: 1
Error: 0x80041002
Code: 80041002
Source: (Null)
0
 
compdigit44Author Commented:
OK since my new CSV does not have Quotes I removed the section of code that removes the quotes. The scripts run but the output file is blank..
0
 
vb_elmarCommented:
Here is a script to obtain the IP address of a network printer. If the function returns '0' the printer isn't online:
Sub GetIP()
SRV = "servername"
Set oWMI = GetObject("winmgmts:\\" & SRV & "\root\cimv2")
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ", , 48)
For Each o In allPrinters
    Length = Len(o.PortName) - 3
    IP = Right(o.PortName, Length)
    WScript.Echo o.ShareName & vbCrLf & IP
Next
End Sub

Open in new window

0
 
compdigit44Author Commented:
OK the works but I need to check the URL because sometime... printer get renamed... so know the port will not help me as much sorry...
0
 
compdigit44Author Commented:
I think this is the problem line

Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & L77)
0
 
vb_elmarCommented:
instead ...
Set oWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & L77)
try ...
Set oWMI = GetObject("winmgmts:" & L77)
0
 
compdigit44Author Commented:
same error...
0
 
vb_elmarCommented:
Did the Msgbox return an 'UNC path' that isn't  misspelled?
To check this I supplied the isPrinterOnline() function with
'on error goto' :
Dim L22, isDeviceOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("filename.csv", 1)
Set outFile = fso.CreateTextFile("output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0) 'read first col of a .csv file
    If L22 <> "Pathname" Then
      isDeviceOnline = isPrinterOnline(L22)
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isDeviceOnline
      outFile.WriteLine L22 & ";" & isDeviceOnline
    End If
Loop
inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Dim o, oWMI, allPrinters
On Error GoTo 99
Set oWMI = GetObject("winmgmts:" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer where Default = 'True'")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
Exit Function
99:
WScript.Echo "Error" & vbCrLf & "->" & L77 & "<-"
End Function

Open in new window

0
 
compdigit44Author Commented:
Error line: "On Error GoTo 99"

States syntax error
0
 
vb_elmarCommented:
instead :
on error goto 99
try :
on error goto on_error

the
99:
has to be replaced by:
on_error
,also
0
 
compdigit44Author Commented:
Same syntax error on line 11 again..
0
 
compdigit44Author Commented:
if am having problems with the powershell script and your reading the CSV file I am wondering if it is my CSV file. I have recreated multiple time though and it does not have quotes but my UNC paths do have spaces..

It it case sensative?
0
 
vb_elmarCommented:
>>Is it case sensitive?
no, It is not case sensitive

>>it does not have quotes but my UNC paths do have spaces
it is allowed in 'UNC paths' to have spaces
0
 
compdigit44Author Commented:
OK I do no understand the syntax error
0
 
vb_elmarCommented:
Does the MsgBox return a clean spelled 'UNC path' if the error occurs?
0
 
vb_elmarCommented:
if the 'UNC path' is clean, try to replace ...
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer where Default = 'True'")
by ...
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ")
0
 
compdigit44Author Commented:
Here is the script that I am running... It now runs but the output.csv file is blank......


Dim L22, isDeviceOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("C:\UNCCheck.csv", 1)
Set outFile = fso.CreateTextFile("C:\output.csv")

inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Dim o, oWMI, allPrinters
Set oWMI = GetObject("winmgmts:" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
Exit Function
WScript.Echo "Error" & vbCrLf & "->" & L77 & "<-"
End Function
0
 
vb_elmarCommented:
Dim L22, isDeviceOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("C:\UNCCheck.csv", 1)
Set outFile = fso.CreateTextFile("C:\output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0) 'read first col of a .csv file
    If L22 <> "Pathname" Then
      isDeviceOnline = isPrinterOnline(L22)
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isDeviceOnline
      outFile.WriteLine L22 & ";" & isDeviceOnline
    End If
Loop
inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Dim o, oWMI, allPrinters
On Error GoTo on_error
Set oWMI = GetObject("winmgmts:" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
Exit Function
on_error:
WScript.Echo "Error" & vbCrLf & "->" & L77 & "<-"
End Function

Open in new window

0
 
compdigit44Author Commented:
Error on line 21 again...
0
 
vb_elmarCommented:
I read an microsoft article. -They write : "VBScript does not support On Error GoTo. -Instead,
use On Error Resume Next and then check the Err.Number"

So, please delete the ...
'on error goto on_error'
statement in the vbs file
0
 
compdigit44Author Commented:
New error....
Synatax error on :     Set oWMI = GetObject("winmgmts:" & L77)
0
 
compdigit44Author Commented:
I have read posting on line that other have had problems with this.. I have tried some of the posted suggestions on no luck
0
 
vb_elmarCommented:
Can you make a MsgBox when the error occurs to check if the 'UNC path' is clean spelled?
0
 
compdigit44Author Commented:
How can I do this?
0
 
vb_elmarCommented:
I added a counter for the MsgBox. In the '10th' query a MsgBox appears
showing the 'UNC path'. This is the line:
If cnt = 10 Then ..
-You can change the value of '10' to the value you want.
Dim L22, isDeviceOnline
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("C:\UNCCheck.csv", 1)
Set outFile = fso.CreateTextFile("C:\output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0) 'read first col of a .csv file
    If L22 <> "Pathname" Then
      isDeviceOnline = isPrinterOnline(L22)
      outFile.WriteLine L22 & ";" & isDeviceOnline
    End If
Loop
inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Static cnt: cnt = cnt + 1
If cnt = 10 Then
   WScript.Echo "cnt = " & cnt & vbCrLf & "->" & L77 & "<-"
End If
Dim o, oWMI, allPrinters
Set oWMI = GetObject("winmgmts:" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
End Function

Open in new window

0
 
compdigit44Author Commented:
Error line 20 expect statement
0
 
vb_elmarCommented:
Dim L22, isDeviceOnline, cnt
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputFile = fso.OpenTextFile("C:\UNCCheck.csv", 1)
Set outFile = fso.CreateTextFile("C:\output.csv")
Do While Not inputFile.AtEndOfStream
    L22 = inputFile.ReadLine
    L22 = Replace(L22, Chr(34), "") 'remove all quotes "
    L22 = Replace(L22, "\ ", "\")   'prevent leading spaces
    L22 = Split(L22, ";")(0) 'read first col of a .csv file
    If L22 <> "Pathname" Then
    cnt = cnt + 1
If cnt = 10 Then
   WScript.Echo "cnt = " & cnt & vbCrLf & "->" & L77 & "<-"
End If
      isDeviceOnline = isPrinterOnline(L22)
      WScript.Echo "->" & L22 & "<-" & vbCrLf & isDeviceOnline
      outFile.WriteLine L22 & ";" & isDeviceOnline
    End If
Loop
inputFile.Close
outFile.Close

Function isPrinterOnline(L77)
Dim o, oWMI, allPrinters
Set oWMI = GetObject("winmgmts:" & L77)
Set allPrinters = oWMI.ExecQuery("Select * from Win32_Printer ")
For Each o In allPrinters
    Select Case o.PrinterStatus
    Case 3
        isPrinterOnline = "PrinterIdle"
    Case 4
        isPrinterOnline = "Printing"
    Case 5
        isPrinterOnline = "WarmingUp"
    Case Else
        isPrinterOnline = "PrinterOffLine"
    End Select
Next
End Function

Open in new window

0
 
compdigit44Author Commented:
Error on line 25   Set oWMI = GetObject("winmgmts:" & L77)
0
 
vb_elmarCommented:
I know the error.

Prior to the error appears you have to make sure the MsgBox
appears and showing you the 'UNC path' which causes the error.

Please set the value in the line
If cnt = 10 Then ...
to the value where the error appears.

This may be ...
If cnt = 1 Then ..
or
If cnt = 31 Then ..
or
If cnt = 860 Then ..

-You have to find it of yourself (by trying).
0
 
compdigit44Author Commented:
Ok  I changed it to "1" and get a message box then the same error on line 25 message
0
 
vb_elmarCommented:
Did the Msgbox return an 'UNC path' that is spelled properly ?

Annotation:
instead of ...
If cnt = 10 Then ..
you can write as well ...
If cnt > 10 And cnt < 15 Then..

-This modification prevents you to click hundreds of MsgBoxes. Then you have to click only
MsgBox 11 , MsgBox 12 , MsgBox 13 and MsgBox 14 .
0
 
compdigit44Author Commented:
The MSGBox did not return the name of the UNC but was blank
0
 
compdigit44Author Commented:
Since he message box pops up when I type in a count of 1 and returns the nothing for the UNC path I can only assume the script is not able to read the CSV file for some reason....  

I will try changing this to a text file tomorrow but do not think it will make a difference.
0
 
compdigit44Author Commented:
I tried created a text file with one know good URL and got the same exact error..
0
 
vb_elmarCommented:
You could start a new thread and ask this question again.
0
 
compdigit44Author Commented:
thank you for all your help ... I start opened a new question :-)
0
 
compdigit44Author Commented:
I wanted to give you created for this because your script is correct and does work for file shares. My problem is that I need it to work with printer shares but did not communicate this correctly in my original posting.
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 46
  • 29
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now