即使以管理员身份运行,也无法写入win7注册表项

编程入门 行业动态 更新时间:2024-10-26 12:32:38
本文介绍了即使以管理员身份运行,也无法写入win7注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 当我尝试在SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run \中创建子项时,出现"UnauthorizedAccessException"异常.

Hi All, "UnauthorizedAccessException" exception appear when i try to create sub key in SOFTWARE\Microsoft\Windows\CurrentVersion\Run\.

try { string TypeLib = "TypeLib"; Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"); RegistryPermission perm = new RegistryPermission(RegistryPermissionAccess.AllAccess, key.Name); perm.AddPathList(RegistryPermissionAccess.Create, key.Name + "\\TypeLibJD"); string[] subKeys = key.GetSubKeyNames(); if (Array.IndexOf(subKeys, TypeLib) >= -1) { RegistryKey typeLibKey = key.CreateSubKey("//TypeLib" ); typeLibKey.SetValue("RunOnStartup", System.Reflection.Assembly.GetExecutingAssembly().Location); } } catch(UnauthorizedAccessException ex) { MessageBox.Show("Cannot Make This Application Run as startup"); }

我通过在app.manifest中编写此应用程序来使该应用程序以管理员身份运行

and i make this app run as administrator by writing this in app.manifest

<pre lang="xml"><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC Manifest Options If you want to change the Windows User Account Control level replace the requestedExecutionLevel node with one of the following. <requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> Specifying requestedExecutionLevel node will disable file and registry virtualization. If you want to utilize File and Registry Virtualization for backward compatibility then delete the requestedExecutionLevel node. --> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> </requestedPrivileges> </security> </trustInfo>

但是UnauthorizedAccessException仍然出现 请帮忙. 在此先感谢.

but the UnauthorizedAccessException still appear Any help please. Thanks in Advance.

推荐答案

假定您要写入HKEY_LOCAL_MACHINE,则需要以提升的特权运行.检查构建属性的清单部分中可用的选项. Assuming you are trying to write into HKEY_LOCAL_MACHINE then you need to run with elevated privileges. Check the options available in the manifest section of your build properties.

当然,您需要以提升的特权运行此类应用程序.即使您已经以管理员身份登录,在Windows 7中,您也需要以管理员身份运行应用程序.请参阅资源管理器上下文菜单.
—SA
Sure, you need to run such application with elevated privileges. Even if you already logged as administrator, in Windows 7 you also need to run your application as administrator. See your Explorer context menu.
—SA

以管理员身份运行应用程序或在项目中使用app.manifest 在清单文件中更改此代码: run your application as administrator or use app.manifest in your project change this code in manifest file : <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC Manifest Options If you want to change the Windows User Account Control level replace the requestedExecutionLevel node with one of the following. <requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> Specifying requestedExecutionLevel node will disable file and registry virtualization. If you want to utilize File and Registry Virtualization for backward compatibility then delete the requestedExecutionLevel node. --> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> </requestedPrivileges> </security>

更多推荐

即使以管理员身份运行,也无法写入win7注册表项

本文发布于:2023-11-11 06:48:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注册表   管理员   身份

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!