Question

I have several scripts that must use UNC paths - not DFS - and would like to be able to determine the UNC path programmatically from the DFS path. For example, we have something like:

\\domain\fs\Home\HomeFolder\MyUserID

and I would like to get from it the UNC path like this:

\\Server1\HomeFolder\MyUserID

I cannot count on a utility like DFSUtil.exe to be available. It will need to be in VBScript.

I found the following code in NET which uses WMI but I can't tease out what's happening to convert it to a usable VBS: http://www.codeproject.com/Tips/158829/Convert-a-file-path-to-a-UNC-Path

Can anyone lend a hand? I'm lost in translation (don't speak NET)...

Was it helpful?

Solution

This is a minimal VBScript translation of what you linked to:

Option Explicit

Dim wmi
Dim col
DIm itm

Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set col = wmi.ExecQuery("Select DeviceID,ProviderName From Win32_LogicalDisk where DriveType=4")

With WScript
  For Each itm in col
    .Echo "========="
    .Echo "DeviceID:" & vbTab & itm.DeviceID
    .Echo "ProviderName:" & vbTab & itm.ProviderName
  Next
End With

Set wmi = Nothing
Set col = Nothing
WScript.Quit

In short, I don't think it is quite what you want... I think you would have to map drives first before running this.

The tidier way to do it would be to run a query against Active Directory to find the DFS share definitions, but where to actually look within AD can be difficult to identify

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top