A
Alan King
To All:
I'm having difficulty getting the syntax correct for VB.NET to produce a
listing of all software applications on a remote PC listed in the registry
installed programs.
I'm able to get to the point where I enumerate the keys, but I can't figure
out the syntax for retrieving the values from those keys. Here's what I
have at this point:
////////////////////// BEGINNING OF CODE
/////////////////////////////////////////
Dim strComputerName As String = tbScope.Text
Dim strSubKeyName As String
Dim strValueName As String
Dim strStringValue As String = ""
Dim strValue As String
Dim strKeyPath As String =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Dim objManagementScope As ManagementScope
Dim objManagementClass As ManagementClass
Dim objManagementBaseObject As ManagementBaseObject
Dim aSubKeys() As String
objManagementScope = New ManagementScope
objManagementScope.Path.Server = strComputerName
objManagementScope.Path.NamespacePath = "root\default"
objManagementScope.Options.EnablePrivileges = True
objManagementScope.Options.Impersonation =
ImpersonationLevel.Impersonate
objManagementScope.Connect()
objManagementClass = New ManagementClass("stdRegProv")
objManagementClass.Scope = objManagementScope
objManagementBaseObject =
objManagementClass.GetMethodParameters("EnumKey")
objManagementBaseObject.SetPropertyValue("hDefKey", CType("&H" &
Hex(RegistryHive.LocalMachine), Long))
objManagementBaseObject.SetPropertyValue("sSubKeyName", strKeyPath)
aSubKeys = CType(objManagementClass.InvokeMethod("EnumKey",
objManagementBaseObject, Nothing).Properties.Item("sNames").Value, String())
Dim strkey As String
For Each strkey In aSubKeys
lbResults.Items.Add(strkey)
Next
////////////////////// END OF CODE /////////////////////////////////////////
In VBScript, I could use the GetStringValue as shown below to get the
Display name of a application listed in the registry:
"GetStringValue(HKLM, BASE_KEY & strKey, "DisplayName", strDisplayName)"
However, I don't know the .NET version (System.Management) of getting these
values.
If anyone has a recommendation or a code snippet to show how I can do this
in VB.NET it would be greatly welcomed.
Alan
I'm having difficulty getting the syntax correct for VB.NET to produce a
listing of all software applications on a remote PC listed in the registry
installed programs.
I'm able to get to the point where I enumerate the keys, but I can't figure
out the syntax for retrieving the values from those keys. Here's what I
have at this point:
////////////////////// BEGINNING OF CODE
/////////////////////////////////////////
Dim strComputerName As String = tbScope.Text
Dim strSubKeyName As String
Dim strValueName As String
Dim strStringValue As String = ""
Dim strValue As String
Dim strKeyPath As String =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Dim objManagementScope As ManagementScope
Dim objManagementClass As ManagementClass
Dim objManagementBaseObject As ManagementBaseObject
Dim aSubKeys() As String
objManagementScope = New ManagementScope
objManagementScope.Path.Server = strComputerName
objManagementScope.Path.NamespacePath = "root\default"
objManagementScope.Options.EnablePrivileges = True
objManagementScope.Options.Impersonation =
ImpersonationLevel.Impersonate
objManagementScope.Connect()
objManagementClass = New ManagementClass("stdRegProv")
objManagementClass.Scope = objManagementScope
objManagementBaseObject =
objManagementClass.GetMethodParameters("EnumKey")
objManagementBaseObject.SetPropertyValue("hDefKey", CType("&H" &
Hex(RegistryHive.LocalMachine), Long))
objManagementBaseObject.SetPropertyValue("sSubKeyName", strKeyPath)
aSubKeys = CType(objManagementClass.InvokeMethod("EnumKey",
objManagementBaseObject, Nothing).Properties.Item("sNames").Value, String())
Dim strkey As String
For Each strkey In aSubKeys
lbResults.Items.Add(strkey)
Next
////////////////////// END OF CODE /////////////////////////////////////////
In VBScript, I could use the GetStringValue as shown below to get the
Display name of a application listed in the registry:
"GetStringValue(HKLM, BASE_KEY & strKey, "DisplayName", strDisplayName)"
However, I don't know the .NET version (System.Management) of getting these
values.
If anyone has a recommendation or a code snippet to show how I can do this
in VB.NET it would be greatly welcomed.
Alan