0

I have a code that launches remote IE. I wish to launch the application with "run as admin" option.
How can this be achieved?

private static void StartSession(string hostName)
{
    var filespec = Path.Combine(GetRootFolderSpec(), "session.rdp");

    if (File.Exists(filespec)) File.Delete(filespec);
    var settings = GetRdpSettings(hostName);
    File.WriteAllText(filespec, settings);
    File.SetAttributes(filespec, FileAttributes.Hidden);
    Process.Start(filespec);
}

private static string GetRdpSettings(string hostName)
{
    return @"redirectclipboard:i:1
    redirectposdevices:i:0
    redirectprinters:i:0
    redirectcomports:i:1
    redirectsmartcards:i:0
    devicestoredirect:s:
    drivestoredirect:s:
    session bpp:i:32
    prompt for credentials on client:i:1
    span monitors:i:1
    use multimon:i:1
    remoteapplicationmode:i:1
    server port:i:1111
    allow font smoothing:i:1
    screen mode id:i:1
    smart sizing:i:1
    promptcredentialonce:i:1
    authentication level:i:2
    gatewayusagemethod:i:2
    gatewayprofileusagemethod:i:0
    gatewaycredentialssource:i:0
    full address:s:" + hostName + @"
    alternate shell:s:||iexplore
    remoteapplicationprogram:s:||iexplore
    gatewayhostname:s:
    remoteapplicationname:s:iexplore.exe
    remoteapplicationcmdline:s:";
}
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
cosmoloc
  • 2,884
  • 5
  • 29
  • 48
  • Do you have any control of the destination computer to be able to add other software that could be run instead of IE? (For example use your own program for the `alternate shell` parameter and have it launch IE elevated then wait for it to be closed.). Also if this was any other application other than IE, I think you would have more options too. Are you always doing IE or did you just choose it for this example? – Scott Chamberlain Feb 24 '14 at 14:48
  • Thanks Scott. For the project i am handling, using IE is a necessity. Destination computer can vary based on different customers. So hardcoding would also be ommitted – cosmoloc Feb 25 '14 at 05:23
  • Hold on a second. Are you wanting to run `mstsc.exe` (the remote desktop program) as a administrator or are you wanting to run `iexplore.exe` on the server you are connecting to as administrator? – Scott Chamberlain Feb 25 '14 at 05:58
  • run iexplore.exe on the server i am connecting to as administrator – cosmoloc Feb 25 '14 at 06:13
  • Then this has nothing to do with `C#` nor `.net`. You are just generating the .RDP file via C# but after that there is nothing involved with that. You will much better luck asking specific questions about RDP on this site or perhaps over on Server Fault. – Scott Chamberlain Feb 25 '14 at 06:16
  • I was hoping for some setting changes within remoteapplicationprogram:s:||iexplore that i might be missing on – cosmoloc Feb 25 '14 at 07:25

1 Answers1

0

If your running on Windows or above

if (Environment.OSVersion.Version.Major >= 6)
{
    processStartInfo.Verb = "runas";
}
simoneL
  • 602
  • 1
  • 7
  • 23
  • Thanks Simone, but if I use processStartInfo, i.e. processStartInfo.FileName=filespec; Process.Start(processStartInfo); the code is unable to identify the path to session.rdp – cosmoloc Feb 25 '14 at 04:58