Reputation: 3304
Below code returns local path from a UNC path.
strPath = "\\pc100\d"
strPath = Replace(strPath, "\\", "")
arrPath = Split(strPath, "\")
strComputer = arrPath(0)
strShare = arrPath(1)
Wscript.Echo strComputer
Wscript.Echo strShare
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Share Where Name = '" & strShare & "'")
For Each objItem in colItems
Wscript.Echo objItem.Path
Next
But it only works for a path of my pc. That is if my pc name is pc1 then if i pass \\pc1\D\ then it returns D:\
But in case i give a network pc path such as \\pc100\d\ then it gives error as shown below
---------------------------
Windows Script Host
---------------------------
Script: D:\Desktop\New Text Document.vbs
Line: 12
Char: 1
Error: Permission denied: 'GetObject'
Code: 800A0046
Source: Microsoft VBScript runtime error
---------------------------
OK
---------------------------
But \\pc100\d\ is a drive which is shared.Firewall is off on both PC.Remote Procedure Call (RPC) service and WMI are running on the PC So why does this gives error.How can i correct it.I do have full permission to that network folder.
Upvotes: 0
Views: 1115