0

I have a C# application and I want to add this application to start-up. I use:

 RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
 Key.SetValue("APPName", "C:\\Program Files\\App\AppName.exe");

My application need Administrator Right to run, I want a method to register my app or to add to trusted applications.

Thanks.

Now I'm using:

        var info = new ProcessStartInfo(
            Assembly.GetEntryAssembly().Location)
        {
            Verb = "runas", // indicates to elevate privileges
        };

        var process = new Process
        {
            EnableRaisingEvents = false, // enable WaitForExit()
            StartInfo = info
        };

        process.Start();

For obtain access only for one method, but now I have problem with

     unauthorizedAccessException was unhandled

I'm trying to create a directory in C:\Program Files.

4

1 回答 1

0

如果您使用 Visual Studio 2010 或 2012,请转到添加新项目 Application Manifest。将请求的执行级别更改为以下:

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

现在,当您的应用程序启动时,它会要求在提升模式下运行。

另一种方法是在提升模式下重新启动应用程序。为此,您不需要应用清单。

您可以在这里阅读这两种技术:http:
//www.codeproject.com/Articles/105506/Getting-Elevated-Privileges-on-Demand-using-C

于 2013-03-27T16:02:03.573 回答