使用vb.net在Windows 7上使用注册表 [英] Working with Registry on WIndows 7 with vb.net

查看:57
本文介绍了使用vb.net在Windows 7上使用注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,该程序在注册表中创建一个密钥来存储项目的信息.该程序可在Windows XP上运行,但在Windows 7上执行时会出现错误.错误消息为不允许请求的注册表访问".下面是发生错误的代码的副本.错误在线:
oReg = Registry.LocalMachine.OpenSubKey("Software",True)

Dim oReg As RegistryKey
试试
oReg = Registry.LocalMachine.OpenSubKey("Software",True)
oReg = oReg.CreateSubKey(RegSubKeyName)
oReg = Registry.LocalMachine.OpenSubKey("Software \\"& RegSubKeyName)
异常捕获
MsgBox(ex.Message)
''Application.Exit()
结束尝试

我一直在网上寻找答案,而我想出的唯一答案是,我必须在执行此代码之前手动设置注册表的权限.这不是我的选择.我将向其他人分发此应用程序,但我不希望他们必须进入reg编辑器并手动设置权限才能使此工作生效.
我可以通过代码做些什么使它工作? Windows 7是否需要做一些不同的事情?

I have a program that creates a key in the registry to store infomration for the project. This program works on Windows XP but gives an error when executed on Windows 7. The error message is "Requested registry access is not allowed". Below is a copy of the code where the error occurs. The error is on the line:
oReg = Registry.LocalMachine.OpenSubKey("Software", True)

Dim oReg As RegistryKey
Try
oReg = Registry.LocalMachine.OpenSubKey("Software", True)
oReg = oReg.CreateSubKey(RegSubKeyName)
oReg = Registry.LocalMachine.OpenSubKey("Software\\" & RegSubKeyName)
Catch ex As Exception
MsgBox(ex.Message)
''Application.Exit()
End Try

I have looked for an answer online and the only answer that I have come up with is that I have to manually set the permissions on the registry before executing this code. This is not an option for me. I will be distributing this app to other people and I do not want them to have to get into the reg editor and manually set permissions to make this work.
Is there anything I can do from code to make this work? Is there something that has to be done different for Windows 7?

推荐答案

您将如何分发该应用程序.您的安装程序可以使用有效权限创建注册表项吗?
How are you going to distribute the app. Can your setup create the registry key with valid permissions?


我已经创建了一个安装项目来分发该应用程序.我为安装创建了一个程序,该程序检查数据库是否已经存在,如果不存在,则将模板数据库复制到正确的位置.我也可以在该代码中创建注册表项.我需要做些什么来设置密钥在生成时的权限吗?
I have created a setup project to distribute the app. I have created a program for the install that checks if the DB already exists and if not copy a template DB to the correct location. I could also create the registry key in that code. Is there something I have to do to set the permissions on the key at the time is is generated?


这篇关于使用vb.net在Windows 7上使用注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆