pearly
(Getting the hang of it)
2004-02-04 06:40 PM
UDF to convert mapped drives to UNC path?

Is there a UDF to convert mapped drives to UNC path? I have tried searching, but to no avail.

Thanks!~


Sealeopard
(KiX Master)
2004-02-04 06:43 PM
Re: UDF to convert mapped drives to UNC path?

You can read this via registry at HKCU\Network or via WMI.

pearly
(Getting the hang of it)
2004-02-04 06:48 PM
Re: UDF to convert mapped drives to UNC path?

Ahh, thanks Jens! I didn't know that before.

Chris S.
(MM club member)
2004-02-04 07:07 PM
Re: UDF to convert mapped drives to UNC path?

There's also WSH...

Code:

Break On

$rc=setoption('explicit','on')
$rc=setoption('novarsinstrings','on')
$rc=setoption('wrapateol','on')

Dim $WshNetwork,$oDrives,$i

$WshNetwork = CreateObject("WScript.Network")
$oDrives = $WshNetwork.EnumNetworkDrives

"Network drive mappings:" ?
For $i = 0 to $oDrives.Count - 1 Step 2
"Drive " + $oDrives.Item($i) + " = " + $oDrives.Item($i+1) ?
Next



pearly
(Getting the hang of it)
2004-02-04 07:43 PM
Re: UDF to convert mapped drives to UNC path?

Thanks Chris! Is there a preferred/reliable method or are they basically all the same?

Les
(KiX Master)
2004-02-04 08:01 PM
Re: UDF to convert mapped drives to UNC path?

Reading the reg has to be the most reliable as WMI and WSH have overhead and dependencies.

Sealeopard
(KiX Master)
2004-02-04 08:05 PM
Re: UDF to convert mapped drives to UNC path?

However, the registry will not contain information about non-persistently mapped drives.

pearly
(Getting the hang of it)
2004-02-04 08:09 PM
Re: UDF to convert mapped drives to UNC path?

Thanks for your quick response, Les and Jens.

Quote:

However, the registry will not contain information about non-persistently mapped drives.




But WMI and/or WSH does?


Sealeopard
(KiX Master)
2004-02-04 08:15 PM
Re: UDF to convert mapped drives to UNC path?

Yes.

Chris S.
(MM club member)
2004-02-05 12:55 AM
Re: UDF to convert mapped drives to UNC path?

There's also a way to retrieve the information using FSO (File System Object), which would be more available (from an operating system standpoint).

Do you have some specific requirements? Do you want to return a collection of all mapped network drives and their UNC path? Do you just want to query a single drive letter?


Radimus
(KiX Supporter)
2004-02-05 01:18 AM
Re: UDF to convert mapped drives to UNC path?

see driveenum() and driveprop() UDFs

pearly
(Getting the hang of it)
2004-02-05 07:50 PM
Re: UDF to convert mapped drives to UNC path?

Quote:

There's also a way to retrieve the information using FSO (File System Object), which would be more available (from an operating system standpoint).

Do you have some specific requirements? Do you want to return a collection of all mapped network drives and their UNC path? Do you just want to query a single drive letter?




Basically when the user browses for a file/folder using GUIDialog (by Lonkero), if it's a mapped drive path, I want to convert to UNC path. I've already implemented the use of the reg. Do you think this is sufficient?


LonkeroAdministrator
(KiX Master Guru)
2004-02-05 08:31 PM
Re: UDF to convert mapped drives to UNC path?

jens, if the reg does not have info on them, how do you then do label in mapdrive?

LonkeroAdministrator
(KiX Master Guru)
2004-02-05 08:35 PM
Re: UDF to convert mapped drives to UNC path?

k, found the info.
it's at:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints

so, info about non-persistent mapped drives IS in registry.


Sealeopard
(KiX Master)
2004-02-05 09:23 PM
Re: UDF to convert mapped drives to UNC path?

Yeah, I was just thinking about HKCU\Network, should know the other location by now ;-)

Chris S.
(MM club member)
2004-02-05 10:08 PM
Re: UDF to convert mapped drives to UNC path?

Give this a try...

Code:

Break On

$nul = SetOption('Explicit','On')
$nul = SetOption('NoVarsInStrings','On')
$nul = SetOption('WrapAtEOL','On')

Dim $sUNC

$sUNC = fnGetUNC('E:\')
$sUNC ?
@ERROR " | " @SERROR ?

Function fnGetUNC($sDrive)
Dim $oFSO,$oDrive

$oFSO = CreateObject('Scripting.FileSystemObject')
If @ERROR Exit @ERROR EndIf

If $oFSO.DriveExists($sDrive)
$oDrive = $oFSO.GetDrive($sDrive)
If $oDrive.DriveType = 3
$fnGetUNC = $oDrive.ShareName
Else
Exit 1
EndIf
Else
Exit 15
EndIf
EndFunction