Start WPF Application with RunAs Prompt

1.2k views Asked by At

So I have a WPF application and here is what I want it to do. I can right click on the executable, select Run As Different user, and get the Windows Security box with User Name and Password, as well as the Smart Card logon. I was wondering if there was a way to launch the Sysinternals Run as Different User to come up automatically, without having to right click and select Run As Different User. Any thoughts?

I was able to go into the Assembly Manifest and force it to run as administrator, but that isn't what I need. I really need the option to run it with Smart Card credentials. Thank you in advance!

1

There are 1 answers

11
Shiva On

AFAIK, the only way to do it that works is by using the RunAs exe as follows. The /savecred will cache credentials, but your user will still have to enter it the very 1st time (which might be annoying for your use-case).

runas.exe  /savecred /user:<localmachinename>\administrator "path to your WPF exe"

or, if you're on a domain:

runas.exe  /savecred /user:<DomainName>\<AdministratorAccountName> "path to your WPF exe"

Example: To Run Visual Studio 2012 in Admin Mode, I tried the following and it worked. I was prompted to enter my password just once, for the 1st time.

runas.exe  /savecred /user:<My_DomainName>\<My_AdministratorAccountName>  "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"

Further Reading: Runas Documentation.