开发者

How can I force the "Run As" form to appear when someone tries to run my .net desktop application?

I need in t开发者_高级运维o 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜