Reputation: 14455
I have a .NET client app that intermittently loses connection to a UNC share where the user is either on a domain or has a local account with the same credentials on the server. Both SO and Google have plenty of examples using LogonUser and WNetAddConnection via P-Invoke, but both require the user's password. All our app needs to do is explicitly open a connection to a UNC, copy a file, and explicitly close the connection without providing credentials -- in other words, using the current credentials. Can anyone point me in the right direction on how to do that in C#?
Upvotes: 1
Views: 1336
Reputation: 1622
According to the documentation of the WNetAddConnection2 function, you can pass in Null for the user name to use the user context of the current process. I assume that means it will use the security context of the account running your client application. MSDN also says to pass in Null for the password to use the password associated with whatever user name is specified.
Maybe setting both to Null will just magically work.
Upvotes: 1