Reputation: 765
I am trying to impersonation a user in my C# code to open a file share in Windows Explorer. BUT IT IS NOT WORKING! My code is below.
Impersonator i = new Impersonator();
using (new Impersonator("userA", "domainA", "pa$$word", LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT))
{
Process.Start(@"c:\windows\explorer.exe", @"\\fileshare\abc");
Response.Write("Impersonated User: " + WindowsIdentity.GetCurrent().Name + "<br />");
Response.Write("Logon User: " + Request.ServerVariables["LOGON_USER"] + "<br />");
Response.Write("Authenticated User: " + Request.ServerVariables["AUTH_USER"] + "<br />")
}
I am using the code to do the impersonation from this site:
http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/
I am thinking it is because the Logon & Authenticated is my windows login because I am using Windows Authentication?
The account I am impersonating is a domain account and has full account to the file share.
Please help
ADDITIONAL:
I also tried using this code but it did not work. I got an "Access Denied" error
string target = "'_blank'";
string script = "window.open(" + @"'file://fileshare/abc'" + "," + target + "," + "'status=no, menubar=yes, toolbar=yes');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "someUniqueId", script, true);
Upvotes: 0
Views: 1686
Reputation: 93424
You can't start Explorer from an asp.net worker process. Explorer is a GUI application that requires a WindowStation to display.
When you say "it doesn't work", do you mean explorer doesn't open up when you go to the web page?
Upvotes: 1