0

Referring to THIS QUESTION I was able to execute some code as different user. Now I'm trying to execute a piece of code as a user with administrator privileges and I get a missing file error. The code is this:

using (new Impersonator("domainAdmin", "DOMAIN", "myStup1dPa$$w0rd"))
{
    GetXAApplicationByName apps = new GetXAApplicationByName();
    apps.BrowserName = new string[] { "*" };
    IEnumerable<XAApplication> result = CitrixRunspaceFactory.DefaultRunspace.ExecuteCommand(apps);
    // other code...
}

The error is thrown at last reported line, the one starting with IEnumerable<XAApplication> and is:

FileNotFoundException not handled C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

I don't report code for Impersonator class, the basic schema is reported on linked question (and it worked also in other applications).

Am I missing something?

Community
  • 1
  • 1
Naigel
  • 9,086
  • 16
  • 65
  • 106

1 Answers1

0

Looks like there is no problem with impersonating but your code somehow tries to load the assembly System.Management.Automation.dll which is not in GAC , can you try registering this assembly in GAC and try it out again .

srsyogesh
  • 609
  • 5
  • 17
  • it's already registered in GAC, and running it without impersonating does work – Naigel Jun 14 '13 at 14:54
  • is it possible for you to catch the exception and see the complete error message (including inner exceptions) using exception.ToString() and see whether you are able to get any info – srsyogesh Jun 14 '13 at 15:32