0

I am developing a c# Winforms application that runs as a normal user (no elivated privilages) under windows7. The application needs to access a folder that is present on another domain - not the domain the user signed in under.

I would like to know how to ask the user to enter the new credentials needed to access the folder and the files it contains, on the other domain, from within the application.

Ideally, I would like to pop-up a credentials dialog, similar to what windows curently does, asking for the userid, password and domain. I am unsure how to do this and what to do with the values the user would provide so the folder's files can be accessed.

An example would be very good.

thanks c# user

user169
  • 1
  • 1

2 Answers2

0

You can used advapi32.dll methods to impersonate a specific user in your code. Have a look at this article.

Community
  • 1
  • 1
Strillo
  • 2,952
  • 13
  • 15
0

You can prompt for details using the CredUIPromptForWindowsCredentials function.

If you're connecting to a file share, you don't need to impersonate a user; you can just pass the other credentials to the WNetAddConnection3 function.

To call it from C#, you'll need P/Invoke.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • If I use CredUIPromptForWindowsCredentials and the user enters thier userid, pwd and domain needed to access the folder. What I dont inderstans is how to use this information to get access. How can I use WNetAddConnection3 to achieve - can you point me to an example? Also, does the user need to be an Administrator to use this approach? – user169 Mar 26 '12 at 20:11