VB读取注册表某一键值后为当前项键值赋予此键值

来源:百度知道 编辑:UC知道 时间:2024/05/24 21:42:15
现在我想点按钮后让它去读取此处注册表键值A

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName
"ComputerName"="A"

为下注册表键值赋值为A:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName]
"ComputerName"="A"

如何实现?
VB代码越简越好

很简单:

第一步:引用WSH对象,,,点击"工程"//// 引用 //// 勾选 windows script host object modle (位置比较靠下)

第二步:添加一个按钮,复制下面的代码,运行即可:

Private Sub Command1_Click()
Dim wshshell As New IWshRuntimeLibrary.wshshell
Dim mypcname As String
mypcname = wshshell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName")
wshshell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\Computername", mypcname
End Sub

“43295811“ 所引用的 wshom.ocx (windows script host object modle)很不安全,经常被木马病毒利用,很多时都被禁用或删除。

还是用API比较好:

Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Lon