1

This query runs fine on my local machine:

strComputer = "."
drive = "C:"
path = "\\path\\to\\local\\folder\\"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery("Select * From CIM_DataFile Where Path = '"&path&"' and drive='"&drive&"'")

If colFiles.Count < 1 Then
    Wscript.Echo "Folder does not exist"
Else
    Wscript.Echo "Folder does exist"
End If

But when I try to query a mapped network drive, the program fails with 'Folders does not exist'. Yet I am sure it is the correct path to the file.

The only parts that change are:

drive = "Z:"
path = "\\path\\to\\mapped\\drive\\folder\\"

Any clues as to why this would not work?

4
  • Using double backslashes like that is not appropriate in vbscript. Commented Oct 18, 2012 at 13:05
  • Ok, but the program runs fine for a local file. And that uses double backslashes. So I don't think it would be the backslashes. Commented Oct 19, 2012 at 9:50
  • Avoid thinking about it. Actually remove the backslashes and try again. What happens? Commented Oct 19, 2012 at 12:08
  • When I remove the backslashes from the path name, I receive an error from windows script host reading 'Invalid query', source SWbemObjectSet, code 80041017. Commented Oct 22, 2012 at 9:04

2 Answers 2

2

Trying to map drives on a remote computer via WMI will fail, though there is a workaround. Thanks to Frank White's inspirational code, a fully fleshed process now exists to map a drive on a remote computer via WMI using a command prompt and passing explicit credentials.

https://stackoverflow.com/a/11948096/1569434

Sign up to request clarification or add additional context in comments.

Comments

0

So to debug this I ran the following:

strComputer = "."
 Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 Set colFiles = objWMIService.ExecQuery("Select * from CIM_Datafile Where Drive = 'Z:'")
 For Each objFile in colFiles
    Wscript.Echo objFile.Name
 Next

This resulted in the error 'remote procedure call failed', which I understand means that the mapped drive does not support WMI.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.