|
API使わなくてもできますけど・・・
1. WSHShellのRegRead, RegWriteを使った方法
'要参照 Windows Script Host Object Model
Dim objWSHShell As IWshRuntimeLibrary.WshShell
Set objWSHShell = New IWshRuntimeLibrary.WshShell
With objWSHShell
.RegWrite "HKCU\Software\Chappi\Test\", 1, "REG_DWORD"
.RegWrite "HKCU\Software\Chappi\Test\hoge", "hogehoge!", "REG_SZ"
Debug.Print CInt(.RegRead("HKCU\Software\Chappi\Test\"))
Debug.Print .RegRead("HKCU\Software\Chappi\Test\hoge")
.RegDelete "HKCU\Software\Chappi\Test\hoge"
.RegDelete "HKCU\Software\Chappi\Test\"
.RegDelete "HKCU\Software\Chappi\"
End With
1. WMIのStdRegProvを用いた方法
Sub EnumPrinters()
Dim objRegProv As Object
Dim strKeyPath As String
Dim vntValueNames As Variant
Dim vntValueTypes As Variant
Dim strValueName As String
Dim strValue As String
Dim i As Long
Const HKCU = &H80000001
Set objRegProv = _
GetObject("winmgmts:\\.\root\default:StdRegProv")
strKeyPath = _
"Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts"
objRegProv.EnumValues HKCU, strKeyPath, _
vntValueNames, vntValueTypes
For i = 0 To UBound(vntValueNames)
strValueName = vntValueNames(i)
objRegProv.GetStringValue HKCU, strKeyPath, _
strValueName, strValue
Debug.Print strValueName & " on " _
& Split(strValue, ",", -1, 0)(1)
Next i
End Sub
|
|