
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
--