Converting logical paths to UNC paths 
Author Message
 Converting logical paths to UNC paths

Hi,

How can I convert a path like "p:\xyz\abc" to "\\server\share\xyz\abc" in
VBScript from an ASP.

I have seen solutions to this written in VB but they require calling
"WNetGetConnectionA" which I dunno how to do from vbscript.

TIA,

John



Mon, 02 Aug 2004 10:39:03 GMT  
 Converting logical paths to UNC paths
Use FSO's GetDrive method to get a Drive object for the P: drive and check the ShareName property...

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hi,

> How can I convert a path like "p:\xyz\abc" to "\\server\share\xyz\abc" in
> vbscript from an ASP.

> I have seen solutions to this written in VB but they require calling
> "WNetGetConnectionA" which I dunno how to do from vbscript.

> TIA,

> John



Mon, 02 Aug 2004 11:21:16 GMT  
 Converting logical paths to UNC paths
Hi Michael,

I've tried using a drive object as you suggested, but unfortunately it is
does not seem to be working. The code I'm using is:

------------------
Dim fso, DriveName, Drive

Set fso = CreateObject("Scripting.FileSystemObject")
DriveName = fso.GetDriveName(Server.MapPath("."))
Set Drive = fso.GetDrive(DriveName)
Response.Write Drive.ShareName
------------------

Drive.ShareName has the value "" and when trying to display it's value in
the immediate window in InterDev, "Device unavailable" is displayed.

Any ideas?

Thanks,

John



Use FSO's GetDrive method to get a Drive object for the P: drive and check
the ShareName property...

--
Michael Harris
Microsoft.MVP.Scripting



Mon, 02 Aug 2004 18:05:50 GMT  
 Converting logical paths to UNC paths
The only way I can think of is to use WMI (or ADSI) to look for a share that has a share.path that matches the path you are looking for.  WMI will enumerate hidden shares and ADSI won't.

Here's a simple WMI Win32_Share example that lists all the shares on the IIS box running the ASP page looking a share that is mapped directly to APPL_PHYSICAL_PATH...

The exact match logic you would use would depend on whether the full path you have is one that is mapped directly to a share or only a leading portion of path would match a share path.

For example,

if the share maps "c:\foo\bar" and the path you have is "c:\foo\bar" then you would be looking for an exact match.

if the share maps "c:\foo\bar" and the path you have is "c:\foo\bar\myfolder" then you would be looking for a share.name match only on a proper leading portion of the path.

<%

set network = createObject("wscript.network")
servername = network.computername
'the above is just to account for running this as a test
'using a URL based on localhost instead a real server name.
'you would probably actually use something like
'servername = Request.ServerVariables("SERVER_NAME")

sPath = lcase(Request.ServerVariables("APPL_PHYSICAL_PATH"))
response.write "APPL_PHYSICAL_PATH = " & sPath & "<br>"

set wmi = getobject("winmgmts:")
wql = "select name,path from win32_share"
set results = wmi.execquery(wql)
for each share in results
  response.write "share.name = " & share.name & " share.path = " & share.path & "<br>"
  if lcase(share.path & "\") = sPath then
    sharename = share.name
    UncPath = "\\" & servername & "\" & sharename
    response.write "Match: " & UncPath & "<br>"
  end if
next

%>

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hi Michael,

> I've tried using a drive object as you suggested, but unfortunately it is
> does not seem to be working. The code I'm using is:

> ------------------
> Dim fso, DriveName, Drive

> Set fso = CreateObject("Scripting.FileSystemObject")
> DriveName = fso.GetDriveName(Server.MapPath("."))
> Set Drive = fso.GetDrive(DriveName)
> Response.Write Drive.ShareName
> ------------------

> Drive.ShareName has the value "" and when trying to display it's value in
> the immediate window in InterDev, "Device unavailable" is displayed.

> Any ideas?

> Thanks,

> John



> Use FSO's GetDrive method to get a Drive object for the P: drive and check
> the ShareName property...

> --
> Michael Harris
> Microsoft.MVP.Scripting



Tue, 03 Aug 2004 00:53:35 GMT  
 Converting logical paths to UNC paths
Hi Michael,

Unfortunately that piece of code wont run on my machine :(

The following line:

set wmi = getobject("winmgmts:")

Kills InterDev with an illegal op when stepped through with debugging. With
debugging disabled, "The page cannot be displayed" comes up accompanied by
the following error:

a.. Error Type:
(0x80041003)
/InterDev_Local/History.asp, line 46
a.. Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461)

So.... I will wrap WNetGetConnection in a COM object and use that from the
script. It's the easiest solution I can think of that I'm 100% sure will
work.

I appreciate your help, thanks,

John


The only way I can think of is to use WMI (or ADSI) to look for a share that
has a share.path that matches the path you are looking for.  WMI will
enumerate hidden shares and ADSI won't.

Here's a simple WMI Win32_Share example that lists all the shares on the IIS
box running the ASP page looking a share that is mapped directly to
APPL_PHYSICAL_PATH...

The exact match logic you would use would depend on whether the full path
you have is one that is mapped directly to a share or only a leading portion
of path would match a share path.

For example,

if the share maps "c:\foo\bar" and the path you have is "c:\foo\bar" then
you would be looking for an exact match.

if the share maps "c:\foo\bar" and the path you have is
"c:\foo\bar\myfolder" then you would be looking for a share.name match only
on a proper leading portion of the path.

<%

set network = createObject("wscript.network")
servername = network.computername
'the above is just to account for running this as a test
'using a URL based on localhost instead a real server name.
'you would probably actually use something like
'servername = Request.ServerVariables("SERVER_NAME")

sPath = lcase(Request.ServerVariables("APPL_PHYSICAL_PATH"))
response.write "APPL_PHYSICAL_PATH = " & sPath & "<br>"

set wmi = getobject("winmgmts:")
wql = "select name,path from win32_share"
set results = wmi.execquery(wql)
for each share in results
  response.write "share.name = " & share.name & " share.path = " &
share.path & "<br>"
  if lcase(share.path & "\") = sPath then
    sharename = share.name
    UncPath = "\\" & servername & "\" & sharename
    response.write "Match: " & UncPath & "<br>"
  end if
next

%>

--
Michael Harris
Microsoft.MVP.Scripting
--



Tue, 03 Aug 2004 11:26:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Converting logical paths to UNC paths

2. Run Minimized

3. Installation problem...

4. Converting local path to UNC path?

5. Help converting UNC paths to physical paths.

6. How to convert local path to UNC-path?

7. How to convert local path to UNC-path?

8. How to convert path to UNC path?

9. Local path vs UNC Path

10. How transform path into unc-path ?

11. turning a local path into a UNC path

12. How to convert file path to UNC?

 

 
Powered by phpBB® Forum Software