Reputation: 289
My program requires access to a certain UNC path, but the path is cross-domain, so depending on the machine the program is being run on, it may or may not have default credentials. Normally, a user would have to just open up explorer and type in the UNC or IP address to get a logon prompt (at which point they can type in appropriate credentials for the domain the share is on).
Is there a "clean" way to test the UNC accessibility, and if the default windows credentials are bad then prompt them for different ones?
Right now I'm using some nasty code to try to read a text file on the share, catch an IOException, and then open an "explorer.exe" Process object (hidden) to get the logon prompt. This is all contained within a loop that checks again after 10s. It sort-of works, but the solution and logic seem really undesirable.
Are my only choices really WNetUseConnection or an interop-style solution?
Upvotes: 5
Views: 3467
Reputation: 74277
Check these articles:
I've used code like this:
new FileIOPermission(FileIOPermissionAccess.Read, path).Demand();
which is supposed to throw a SecurityException
if you don't have the desired access, but for paths on network drives or UNC paths, the FileIOPermission.Demand()
method appears to be a no-op.
Upvotes: 3
Reputation: 2146
I have never done this, but what you may be asking to do is check the Access Control List (ACL) in NTFS.
I did a web search for c# and "Access Control List" and got a couple of hits that may be of interest to you. This may be cleaner, but it may not be easier that what you are already doing.
Upvotes: 0