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!

Script to check whether file on my own computer doesn't work

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
US
Hello,

I am following along

Managing Windows® with VBScript and WMI
Don Jones
Addison-Wesley Professional
English, 2004, 640 pages
ISBN/ISSN: 0-321-21334-3


And am using their script

Code:
Option Explicit

Dim varServer, varFile, objFS, varFoundNone, objRes

 ' first, get the server name [not IP address] we want to work with
varServer = InputBox ("Server name to check")

' get the local path of the file to check. Must start with drive letter, and cannot be UNC
varFile= InputBox _
 ("Full path and filename of the file on the " & _
 "server (use the local path as if you were at the " & _
 " server console)")

' bind to the server's file service. Uses Active Directory Services Interface (ADSI) to connect to 
' server's file service
set objFS = GetObject("WinNT://" & varServer & "/lanmanserver,fileservice")

' scan through the open resources until we
' locate the file we want
varFoundNone = True

' use a FOR...EACH loop to walk through the
' open resources
For Each objRes in objFS.Resources

     ' does this resource match the one we're looking for?
     If objRes.Path = varFile then

          ' we found the file - show who's got it
          varFoundNone = False
          WScript.Echo objRes.Path & " is opened by " & objRes.User
 
     End If

Next


' if we didn't find the file open, display a msg
if varFoundNone = True then
     WScript.Echo "Didn't find that file opened by anyone."
end if

However, when I try it on my own computer, and choose a file that I opened, I always get the output

"Didn't find that file opened by anyone"

The file exists and I opened it.

What gives?
 
is your computer running a server OS with Active Directory installed and congifured? If not, that probably why (just a guess).

to see if a file exists on the local machine:
Code:
set objFSO = CreateObject("Scripting.FileSystemObject")

strFile = inputBox ("FilePath:")
if (objFSO.FileExist(strFile)) then
   msgbox "yep"
else
   msgbox "nope"
end if

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
then that's why

' bind to the server's file service. Uses Active Directory Services Interface (ADSI) to connect to ' server's file service

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top