-2

I can't find a C# library to use startInfo.Verb="runas". Please tell me where I can find it.

using ???;
...
startInfo.Verb="runas";
Lazar Galić
  • 3
  • 1
  • 4
  • 1
    What type is `startInfo` object of? Your question is unclear and you down vote then. You want your app to require Administrator permissions? – Ryan Apr 23 '17 at 00:20
  • I actually found on several places code that uses startInfo, and I believed it was predefined in some library. However, your solution worked, so thanks anyway – Lazar Galić Apr 23 '17 at 09:15

3 Answers3

2

In order to run your application only with administrator permissions, first of all, you should add manifest file to your application.
You can do it in VS 'Add -> New Item -> Applicatoin Manifest File'.
Then find this line on it:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

Then change level attribute value to requireAdministrator.
After all you need is to include your manifest in PE-exe resources. In manifest properties change Build Action item to Embedded Resource.
This procedure worked for me. You can find more details about manifest here.

UPDATE
I did not find a way to make this programmatically.
People guess there is no way for application to level upo its own permissions programmatically,
Please, read attentively comments for latest answers here

Community
  • 1
  • 1
Ryan
  • 609
  • 6
  • 13
0

Use this namespace

using System.Diagnostics;
Ali Humayun
  • 1,756
  • 1
  • 15
  • 12
0

I am not 100% sure, but i think the documentation of what your looking for is on the Microsoft website, here

I think you should include these as well

using System;
using System.Diagnostics;
using System.ComponentModel;
BlooB
  • 955
  • 10
  • 23
  • I do not understand the down vote, as the documentation shows this information, if any one wants to down vote its their right, however you should indicate the reason to ensure the same problem does not happen again in the future. – BlooB Apr 23 '17 at 00:05
  • I don't understand the downvotes either - did someone just come through and blindly downvote all of the answers to the question? – EJoshuaS - Stand with Ukraine Apr 23 '17 at 03:25
  • I believe so sir – BlooB Apr 23 '17 at 03:36