win7 注册表读写的问题

hanshuangfly 2010-05-27 09:50:56
目前遇到一个项目,需要在win7下读写注册表信息,请问大家有什么好的办法?

条件如下:

1.0 利用dll完成该功能。

2.0 不需要用户使用administrator用户登录,就可以完成修改注册表的操作。
...全文
622 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
6742 2011-09-08
  • 打赏
  • 举报
回复
KeyStr,上边没有定义,呵呵 是 string
6742 2011-09-08
  • 打赏
  • 举报
回复
我也想了解注册读写的问题,在XP、VISTA中好像没有问题,但在WIN 7中有点问题。我的程序如下

Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const REG_DWORD As Long = 4
Private Const REG_SZ As Long = 1

'本子程序主要是将程序与ABC关联
Sub GLabc()
Dim hKey As Long, ret1 As Long

hKey = HKEY_CLASSES_ROOT

'扩展名
RegSetValue hKey, ".abc", REG_SZ, "abc_auto_file", 13
'类型描述
RegSetValue hKey, "abc_auto_file", REG_SZ, "abc文件", 11

'shell设置默认值
RegSetValue hKey, "abc_auto_file" & "\shell", REG_SZ, "open", 4
'命令
KeyStr = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34) & " " & Chr(34) & "%1" & Chr(34)
RegSetValue hKey, "abc_auto_file" & "\shell\open\command", REG_SZ, KeyStr, LenB(KeyStr)

'打印
KeyStr = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34) & " " & Chr(34) & "/p" & Chr(34) & " " & Chr(34) & "%1" & Chr(34)
RegSetValue hKey, "abc_auto_file" & "\shell\print\command", REG_SZ, KeyStr, LenB(KeyStr)

'图标
KeyStr = Chr(34) & App.Path & "\Musical Note.ico" & Chr(34)
RegSetValue hKey, "abc_auto_file" & "\DefaultIcon", REG_SZ, KeyStr, LenB(KeyStr)

RegCloseKey hKey
MsgBox "关联成功!", vbInformation + vbOKOnly
end sub

不知道为什么上边的RegSetValue并不能运行成功?
hanshuangfly 2010-05-31
  • 打赏
  • 举报
回复
everyone,用户,就是点击文件属性,安全里边,就会有一个everyone用户,只有这样的用户才能是所有人员都有权限进行操作吧。
老马何以识途 2010-05-28
  • 打赏
  • 举报
回复
我也想解决这个问题,不过我不是dll操作,只是想直接以超级管理员运行。正在考虑Windows 7的UAC白名单,楼主可以参考参考。
曹大夯 2010-05-28
  • 打赏
  • 举报
回复
你是说Registry Functions么?
http://msdn.microsoft.com/en-us/library/ms724875(v=VS.85).aspx
RegOpenKeyEx,
RegCloseKey,
RegCreateKeyEx,
hanshuangfly 2010-05-28
  • 打赏
  • 举报
回复
有没有大人继续给一些win7下读写注册表的问题
曹大夯 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 hanshuangfly 的回复:]

Huntercao:我试了好几种提升权限的方法,在运行修改LOCAL_MACHINE的时候,都提示我需要管理员权限才行??这个如何解决呀?还有,我还发现,我使用提升权限的方式,提升后发现只有everyone用户了,但是为什么everyone具有的是特殊权限哪?
[/Quote]

那是肯定的。修改HKLM必须有管理员权限才行。这个是绕不过去的。

everyone用户是什么意思?指的是all users的user group么?
hanshuangfly 2010-05-28
  • 打赏
  • 举报
回复
Huntercao:我试了好几种提升权限的方法,在运行修改LOCAL_MACHINE的时候,都提示我需要管理员权限才行??这个如何解决呀?还有,我还发现,我使用提升权限的方式,提升后发现只有everyone用户了,但是为什么everyone具有的是特殊权限哪?
hanshuangfly 2010-05-27
  • 打赏
  • 举报
回复
非常感谢!我再找找。win7搞的人好头疼呀。
曹大夯 2010-05-27
  • 打赏
  • 举报
回复
也是。

你可以考虑将这个问题跑到VC/MFC - ATL/ActiveX/COM去问问。也许那边大拿比较多,可以给你更多的指示。

搜了一下MSDN,这个链接可能对你也有用:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/21907f09-69e7-459e-82ba-287a3f075848
//------------------------------------
I think that the self-elevation solution and the launch of a separate process to do adminitrative tasks are the best practices here.

Another solution is to install a Windows Service with your application. The Windows Service is configured to run as admin or as SYSTEM. The service is responsible for all administrative tasks. You application that is run as a restricted admin inter-process-communicate with the Windows Service. In this way, you even will not see the elevation UI.
//-------------------------------------
或者,用:
COM out of process or process restart.
hanshuangfly 2010-05-27
  • 打赏
  • 举报
回复
可是关键的问题是,我的是个DLL库呀,只是在调用的时候,才需要修改注册表,我发现win7并没有给出提示。
曹大夯 2010-05-27
  • 打赏
  • 举报
回复
其实你的代码里面不需要做特殊处理。
一旦你的程序需要Elevate Privilege,系统在运行你的程序的时候会自动将权限提升的Dialog显示出来的。
曹大夯 2010-05-27
  • 打赏
  • 举报
回复
可以参考:
http://support.microsoft.com/kb/981778

How to self-elevate the current process
How to automatically elevate the process when it starts up
hanshuangfly 2010-05-27
  • 打赏
  • 举报
回复
没有人遇到win7的问题吗
hanshuangfly 2010-05-27
  • 打赏
  • 举报
回复
在程序中,提升用户权限,如何提升有没有代码?或者参考来试试。
曹大夯 2010-05-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hanshuangfly 的回复:]

首先,感谢楼上的回答,或者可以这样说,有没有什么办法,再程序里边提升操作权限为administrator,而不需要用户自己去以administrator登录,从而间接完成注册表的读写哪
[/Quote]
用户不需要以administorator登录吧。用户只会看到"User Account Control"关于提升用户权限的警告框,在用户选择继续之后,还是用原来的用户进行操作。

好像是没有简单的方法绕过这个警告框。

可以建议用户自己去Disable UAC来抑制警告框的出现;

或者有人试过:在程序中提升用户权限,然后用在程序中,找到“User Account Control”窗口,并给该窗口的"continue"button 发送click消息;在没有用户干预的情况下,完成用户权限提升。不太建议做这种系统不提倡的事情。
hanshuangfly 2010-05-27
  • 打赏
  • 举报
回复
首先,感谢楼上的回答,或者可以这样说,有没有什么办法,再程序里边提升操作权限为administrator,而不需要用户自己去以administrator登录,从而间接完成注册表的读写哪
曹大夯 2010-05-27
  • 打赏
  • 举报
回复
用注册表操作的API就好了。

->不需要用户使用administrator用户登录,就可以完成修改注册表的操作。
很多注册表项的内容更改必须用administrator权限的。

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧