views:

33

answers:

2

Hi,

I need in to popup thr "Run As" form when user tries to run my application (C#.NET 4, on Win XP), that he could easily to log as other user. It may be in the application itself (in the C# code) or in some other preceeding batch/exe file ("launcher") or such. I didn't find any way to pop this form. How could it be done?

thanks.

A: 

With <requestedExecutionLevel level="requireAdministrator"/> in your manifest, you can force your application to be run as administrator. This however does not include the RunAs dialog. If you look at the settings from the shortcut, you see that there also is no option there to handle this.

When the current user has administrative privileges, the described setting will simply ask the user to run it as administrator. However, when the current user does not have this privilege, it will ask the user to enter the details of an administrative account, which I think comes close to what you're looking for.

Pieter
+1  A: 

Your best bet if you want to do this is create a bootstrap process that calls CredUIPromptForWindowsCredentials. This will create a dialog that will prompt the user for credentials. Once you have their credentials, then use the overload of Process.Start which takes in a username and password that the CredUIPromptForWindowsCredentials gave back. Requires a little bit of Interop.

vcsjones