0

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.

IT researcher
  • 3,274
  • 17
  • 79
  • 143

2 Answers2

1

You don't have access to the WMI/ManagementScope on PC100.

Mesh
  • 6,262
  • 5
  • 34
  • 53
  • ok.But can it be done by enabling something or changing settings? – IT researcher Jul 30 '13 at 09:36
  • If you are using AD then your account needs to be a member of a group that is a member of PC100's Administrators(or Power Users) group. If you using Workgroups then I think you just have to have an account created on PC100 that has the same name as yours and added to the Admin/PU group on that machine – Mesh Jul 30 '13 at 11:18
  • I am using workgroup.But i do have same account created in both PC.but still getting same error – IT researcher Aug 07 '13 at 09:16
  • Is Windows Management Instrumentation Service running on that PC? – Mesh Aug 07 '13 at 12:22
  • Are you using Visual Studio? can you connect to the other machine via the Server Explorer? There is another tool Called CIM Studio that lets you browse WMI stuff too http://www.microsoft.com/en-gb/download/details.aspx?id=24045 – Mesh Aug 07 '13 at 14:15
  • There may be a couple of more steps to take...From what i've found, when you connect to a remote machine windows forces you to connect as Guest. You can change a registry setting which, will allow the connection to use the caller's account. See this article http://www.homesignals.com/home-automation/using-vbscript-and-wmi-to-interrogate-pcs-in-a-workgroup.html – Mesh Aug 19 '13 at 08:18
  • Although, you may be able to avoid the registry fiddle by using SWbemLocator object to establish the connection to the remote machine, http://msdn.microsoft.com/en-us/library/aa393720(v=vs.85).aspx – Mesh Aug 19 '13 at 08:19
1

Do you have to get your WMI object like this instead?:

Set objWMIService = GetObject("winmgmts:" & _
    "{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2")

Source: MSDN

Jobbo
  • 1,358
  • 1
  • 8
  • 21