4

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 Answers1

1

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.

Shiva
  • 20,575
  • 14
  • 82
  • 112
  • Thanks - I see what you are getting at. What I am looking for is a smidge different I think. I am looking to have the WPF application open itself with the prompt, not open another program. My program is an Active Directory replacement that requires I IT staff to use their security token to reset passwords. I can't have it run as administrator, but need to have the entire application use the Smart Card credentials. Does that make sense? – user3050992 Nov 30 '13 at 01:02
  • So basically I am starting with the desktop and am clicking on the icon for my executable that is created through WPF. – user3050992 Nov 30 '13 at 01:02
  • Yes, that makes sense. Sorry my answer didn't help. I'll keep looking and let you know if I find out a way... – Shiva Nov 30 '13 at 01:05
  • Actually I think you could be on to something - looking in the Runas Documentation there is a /smartcard option stating - Indicates whether the credentials are to be supplied from a smartcard. This parameter cannot be used with the /savecred parameter. – user3050992 Nov 30 '13 at 01:07
  • Cant you right click the exe file and select always run as administrator? – atomaras Nov 30 '13 at 01:07
  • wonder if there would be a way to start the entire application that way. – user3050992 Nov 30 '13 at 01:07
  • Cool. Try it and let us know if it works. I'm heading home now, will logon later and also try it. – Shiva Nov 30 '13 at 01:08
  • Atomaras - Don't want to run as administrator though - want to run with smartcard creds – user3050992 Nov 30 '13 at 01:08
  • @Shiva - So I was able to sort of get it... I started a command prompt and typed the folloing: runas /smartcard /user:\ "path to exe" and it worked. Any thoughts on how to integrate this into the application - perhaps without using a cmd prompt? – user3050992 Nov 30 '13 at 01:40
  • @kenny Not really - ideally I just want to click on the icon to bring up the different "run as different user" options. I was able to create a shortcut to my application and then in the target add C:\Windows\System32\ShellRunas.exe before the target - which works the way I want it to, however, I can't seem to emulate it within C# – user3050992 Nov 30 '13 at 04:43
  • Sounds like a custom app then. – kenny Nov 30 '13 at 11:44