随笔 - 102  文章 - 0 评论 - 65 阅读 - 20万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

引入:using Microsoft.Win32;

(1)读取注册表信息

代码:

RegistryKey rsg = null;                   
 rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\isBIM\\isBIMQS2017\\Revit2016", false);
string PackageLocation = rsg.GetValue("InstallationLocation").ToString();

第二行的 true/false表示是否可修改

(2)写入注册表信息

代码:

string isBIMProductsInfo = String.Format("SOFTWARE\\YourPath\\{0}\\{1}", path1,path2);
RegistryKey isBIMProductRsg = Registry.LocalMachine.OpenSubKey(isBIMProductsInfo, RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
isBIMProductRsg.SetValue("YourProperty", YourNewValue);

注意:你可能会被提示没有权限去操作注册表,特别是LocalMachine下的注册表信息,所以你需要:
1)在项目中右键添加应用清单文件app.manifest

2) 修改requestedExecutionLevel:

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

这样当程序运行到修改注册表的值时会弹出提示框,提示是否能修改注册表,即请求管理员"requireAdministrator"。

posted on   airforce094  阅读(603)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示