具有管理员权限的C#程序未在windows上启动

具有管理员权限的C#程序未在windows上启动,c#,autostart,admin-rights,C#,Autostart,Admin Rights,如何使用管理员权限以编程方式创建autostart?我试过了 using (var registryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", true)) + { + registryKey.SetValue(System.Windows

如何使用管理员权限以编程方式创建autostart?我试过了

using (var registryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", true))
+            {
+                registryKey.SetValue(System.Windows.Forms.Application.ExecutablePath, "RUNASADMIN");
+                registryKey.Flush();
+                registryKey.Close();
+            } 

但即使UAC窗口也不会出现。

您不能这样做。相反,使用服务。来自当前用户的服务无法正常工作。您需要让服务与非管理员本地进程对话。我不明白。如何获得具有服务的应用程序的管理员权限?