Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing For NULL objects in VBScript

Status
Not open for further replies.

msu

Technical User
Apr 10, 2003
2
AU
I am trying to test for the existance of shares on a server. I can create a reference to the Lanmanserver object and enumerate the names of the existing shares but if there are no shares the script fails with and "Object required error" I know this is something simple but...

Sample script:

Dim fs,share
Set fs = GetObject("WinNT://computername/LanmanServer")

For Each share In fs
MsgBox("Share: " & share.name)
MsgBox ("Path: " & share.path)
Next
 
I had a similar issue with something like this, and what I did was I set before the for each a variable of i = 1. Within my ForEach I incremented the variable with i=i+1. After the for each was finished, I had the code check if i was still = 1, if it was, it displayed a "No Records" message, if it was not = 1 it proceded normally.
 
Thanks, I had gone down that path and it didn't work it out at first. What was going wrong was that the count would increment based on the admin shares but the enumeration can not handle it. I may be able to work that out with the Drive object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top