C# 试图在c注册表中执行未经授权的操作
我想使用c应用程序更改浏览器主页 我知道在internet explorer中我必须更改注册表 我使用这个代码C# 试图在c注册表中执行未经授权的操作,c#,C#,我想使用c应用程序更改浏览器主页 我知道在internet explorer中我必须更改注册表 我使用这个代码 RegistryKey startPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", RegistryKeyPermissionCheck.ReadWriteSubTree,RegistryRights.WriteKey); st
RegistryKey startPageKey =
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main",
RegistryKeyPermissionCheck.ReadWriteSubTree,RegistryRights.WriteKey);
startPageKey.SetValue("Start Page", "http://stackoverflow.com");
startPageKey.Close();
但出现这种错误:
System.UnauthorizedAccessException was unhandled
HResult=-2147024891
Message=Attempted to perform an unauthorized operation.
Source=mscorlib
StackTrace:
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in D:\Users\eng-mayer\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in D:\Users\eng-mayer\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
-http
://victorhurdugaci.com/using-uac-with-c-part-1/
://victorhurdugaci.com/using-uac-with-c-part-2/
://victorhurdugaci.com/using-uac-with-c-part-3/
@
希望这有帮助 是否需要提升来更改注册表?这正是{试图执行未经授权的操作。}