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
well, you'll need to check a couple things:
    1.    is Server.MapPath(".") returning a valid path?
    2.    is said path really on a mapped drive?

If GetDrive is given a name of a local disk, ShareName property is blank.
Also, if DriveName is not assigned to a particular drive at the time,
ShareName is blank.

-K


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



Mon, 02 Aug 2004 21:06:41 GMT  
 Converting logical paths to UNC paths


Quote:
> well, you'll need to check a couple things:
>     1.    is Server.MapPath(".") returning a valid path?

Yes

Quote:
>     2.    is said path really on a mapped drive?

Yes

Quote:
> If GetDrive is given a name of a local disk, ShareName property is blank.
> Also, if DriveName is not assigned to a particular drive at the time,
> ShareName is blank.

The ShareName property is the only one that is empty, the rest of the
properties have the expected values.

Is the functionality of "WNetGetConnection" available in an existing COM
object? It looks like easiest solution will be to make a COM object in VB6
that wraps "WNetGetConnection", and then use an instance of that object from
VBScript. I was hoping there might be a simpler way.

John



Mon, 02 Aug 2004 21:43:23 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  
 
 [ 7 post ] 

 Relevant Pages 

1. Converting logical paths to UNC paths

2. Converting local path to UNC path?

3. Help converting UNC paths to physical paths.

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

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

6. How to convert path to UNC path?

7. Local path vs UNC Path

8. How transform path into unc-path ?

9. turning a local path into a UNC path

10. How to convert file path to UNC?

11. Convert Path to UNC

12. Convert path to UNC

 

 
Powered by phpBB® Forum Software