GetFullPath and Administrator Paths

G

Guest

I am trying to see if two file references are equal using the
Path.GetFullPath method. The following two paths when passed to this method
do not come back the same, which surprises me.

"\\MyMachine\C$\Data\MyData\MyFile.txt"
"C:\Data\MyData\MyFile.txt"

These are logically the same file, but GetFullPath returns the path passed
in for each. I would have expected the first to come back like the second
(without machine name and C$).

If this is the expected behavior, what can I use to test them for
equivalence? I could parse for $, but that seems kludgy.
 
J

Jeffrey Tan[MSFT]

Hi Brian,

I do not think Path.GetFullPath method can be used to achieve your task.
Just as documented in MSDN, Path.GetFullPath method uses current directory
and current volume information to fully qualify path. If you specify a file
name only in path, GetFullPath returns the fully qualified path of the
current directory. It will not search the entire file system to find if the
file you passed existed.

So the filename is not required to exist. For example, if c:\temp\newdir is
the current directory, calling GetFullPath on a file name such as test.txt
returns c:\temp\newdir\test.txt. The file need not exist.

Can you tell me what two file references do you want to compare? Do you
have 2 FileInfo objects? If so, I think you may compare FileInfo.FullName
to determine if they are the same.

If you want to determine the local file system full path of the UNC file
share, you have to p/invoke Win32 API NetShareGetInfo. The link below
contains some C++ sample regarding using this API, you may convert it into
.Net:
http://win32.mvps.org/network/nsgi.cpp

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Is there another method from Win32 that I could use that doesn't require
administrator privilege?

NetShareGetInfo requires privileges when asking for level 2 or higher
details. Level 2 and above are the only levels that wil tell you the local
path.

Is there an alternative? Thanks,
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Thank you for the feedback.

Yes, I can reproduce this behavior. It seems that NetShareGetInfo requires
Administrator right to call for SHARE_INFO_2. I have tried to contact the
NetShareGetInfo API owner team to confirm if this is by design and if there
is any other way to workaround this Administrator right requirement. If
this is by design, I do not think there is any other way to query this
without Administrator right, because if the other way existed, it will
become a security hole of this design.

Anyway, I will get back to you ASAP. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Sorry for letting you wait.

I have discussed this issue with the dev team.

Per MSDN (http://msdn2.microsoft.com/en-us/library/aa380482.aspx)
"Only members of the Administrators, Server Operators, or Power Users local
group, or those with Print or Server Operator group membership, can
successfully execute the NetShareGetInfo function at level 2. No special
group membership is required for level 0 or level 1 calls."

In Vista, non-admins are able to query at level 2 for local shares, but not
against remote machines. For remote machines, you either need Power
User/Admin/server Operator group permissions (the latter group I believe is
deprecated, and Power Users may also be in Vista).

If your infrastructure wanted to allow the normal user to access remotely,
you could write an agent to gather share information locally and send it to
the server.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I had read that in the documentation and was looking for an alternative. We
are not running our app on Vista yet, so I cannot count on being able to
call version 2.

All I am interested in translating are local shares. I looked at the File
and FileInfo objects to see if they offered an operator== that would let you
know if they were the same, but I didn't see one.

Is there a way to see if they are the same that I might have missed. It is
expected that my application user will have access to these files.
 
J

Jeffrey Tan[MSFT]

Hi Brian,

Thank you for the feedback.

I do not think File/FileInfo == operator is useful here. This operator will
only check if 2 objects are equal. It can not know if these 2 file objects
pointed to the same local file/directory. You should use FileInfo.FullName
property to compare their absolute full path.

The only problem left is the UNC share folder path, which is different from
the local NTFS path. We have 2 solutions in this scenario:
1. Embed admin username/password in the application, so that you can
impersonate the Administrator and call NetShareGetInfo
2. Writing an agent application which runs under Administrator account.
This agent application can call NetShareGetInfo to retrieve the local
absolute path and pass it to your non-admin application for comparison.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top