WMI--Work With Registry

'''''''''''Read values from registry
HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&"."& "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Control\hivelist"
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,arrValueNames, arrValueTypes
For i=0 To UBound(arrValueNames)
    print "File Name: " & arrValueNames(i)      
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,arrValueNames(i),strValue
    print "Location: " & strValue
Next
---------------------------------------------------------------------
''''''''' Create a new registry Key and values
HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&"." & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Regnewv1"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
strValueName = "vname1"
strValue = "venkat"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValueName = "DWORD Value Name"
dwValue = 82
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
---------------------------------------------------------
'''''''''''Delete Registry key Values
HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &"."& "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Regnewv1"
strDWORDValueName = "DWORD Value Name"
strExpandedStringValueName = "Expanded String Value Name"
strStringValueName = "vname1"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName
----------------------------------------------------------------------------------------------------------------------
'''''''Delete registry key
HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &"."& "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Regnewv1"
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
---------------------------------------------------------------------------
'''''''''Display List of softwares installed in the system
Set wmi=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &"." &"\root\cimv2")
Set sc=wmi.ExecQuery("SELECT * FROM Win32_Product")  
If sc.Count > 0 Then
    Set fs=CreateObject("Scripting.FileSystemObject")
    Set f=fs.CreateTextFile("d:\SoftwareList.txt", True)
     For Each sl in sc
        f.WriteLine sl.Caption & vbtab &sl.Version
    Next
    f.Close
Else
    Msgbox "Cannot retrieve software from this computer."
End If

Comments