wmi >> Querying a remote machine registry using WMI and VB.NET

by SkpH » Wed, 10 Nov 2004 00:28:10 GMT

Hello. I'm not sure if this is the right forum, so please let me know what
is the correct one if it isn't.

I've been puzzled by this a for a few days. I'm trying to read a registry
value from a remote system's registry using WMI (System.Management). I'm
able to connect to the system and even run a process, but I cannot figure out
what is I have to do to get the StdRegProv process. Here is what I am doing:

Dim wmiOptions As New ConnectionOptions
wmiOptions.Username = "username" 'Administrator's login and pwd.
wmiOptions.Password = "password"
wmiOptions.Impersonation = ImpersonationLevel.Impersonate

Dim wmiScope as New ManagementScope("\\" & pAddress & "\root\cimv2",
wmiOptions)

Dim wmiPath As New ManagementPath("Win32_Service")
Dim processClass As New ManagementClass(wmiScope, wmiPath, Nothing)
Dim inParams As ManagementBaseObject =
processClass.GetMethodParameters("GetStringValue")

I know that the inParams fails because I have the Win32_Service, not the
StdRegProv, but how do I get the StdRegProv?

I tried querying instead of instanciating the ManagementClass directly, but
I get nothing returned:

Dim query As New SelectQuery("Win32_Service", "Name='StdRegProv'")
Dim searcher As New ManagementObjectSearcher(wmiScope, query)
Dim envVar As ManagementBaseObject
For Each envVar In searcher.Get()
... <-- There is nothing in envVar.
Next

I am using WMI because although I don't have domain rights to the systems
(otherwise I'd use RegistryKey.OpenRemoteBaseKey...although if anyone can
tell me how to use this with a provided username/password, it would be
great), I have usernames/passwords with administrator rights. I was able to
create a process remotely, so I know that access rights is not the problem.

Any help, alternative method, or pointer to a solution would be appreciated.

JJG

wmi >> Querying a remote machine registry using WMI and VB.NET

by Peter Falz » Wed, 10 Nov 2004 00:55:07 GMT


Hi JJG,



take a look at:
http://www.dotnet247.com/247reference/msgs/45/229075.aspx

There is an example in C#.
HTH

Cioa
Peter

wmi >> Querying a remote machine registry using WMI and VB.NET

by SkpH » Wed, 10 Nov 2004 01:35:02 GMT

Thanks. After a few tweaks from the article you indicated, I'm able to
create the object.

wmi >> Querying a remote machine registry using WMI and VB.NET

by Noname » Wed, 10 Nov 2004 15:20:33 GMT


please let me know what
to read a registry
(System.Management). I'm
but I cannot figure out
Here is what I am doing:
login and pwd.
ImpersonationLevel.Impersonate
& "\root\cimv2",
wmiPath, Nothing)
Win32_Service, not the
ManagementClass directly, but
("Win32_Service", "Name='StdRegProv'")
(wmiScope, query)
rights to the systems
RegistryKey.OpenRemoteBaseKey...although if anyone can
username/password, it would be
rights. I was able to
is not the problem.
would be appreciated.

In C#
ManagementClass man = new ManagementClass(wmiScope, new
ManagementPath("StdRegProv"), null);

Similar Threads

1. Querying a remote machine registry using WMI and VB.NET

Hello.  I'm not sure if this is the right forum, so please let me know what 
is the correct one if it isn't. (I posted this one also to the 
win32.programmer.wmi forum).

I've been puzzled by this a for a few days.  I'm trying to read a registry 
value from a remote system's registry using WMI (System.Management).  I'm 
able to connect to the system and even run a process, but I cannot figure out 
what is I have to do to get the StdRegProv process.  Here is what I am doing:

   Dim wmiOptions As New ConnectionOptions
   wmiOptions.Username = "username"    'Administrator's login and pwd.
   wmiOptions.Password = "password"
   wmiOptions.Impersonation = ImpersonationLevel.Impersonate

   Dim wmiScope as New ManagementScope("\\" & pAddress & "\root\cimv2", 
wmiOptions)

   Dim wmiPath As New ManagementPath("Win32_Service")
   Dim processClass As New ManagementClass(wmiScope, wmiPath, Nothing)
   Dim inParams As ManagementBaseObject = 
processClass.GetMethodParameters("GetStringValue")

I know that the inParams fails because I have the Win32_Service, not the 
StdRegProv, but how do I get the StdRegProv?  

I tried querying instead of instanciating the ManagementClass directly, but 
I get nothing returned:

   Dim query As New SelectQuery("Win32_Service", "Name='StdRegProv'")
   Dim searcher As New ManagementObjectSearcher(wmiScope, query)
   Dim envVar As ManagementBaseObject
   For Each envVar In searcher.Get()
      ...  <-- There is nothing in envVar.
   Next
  
I am using WMI because although I don't have domain rights to the systems 
(otherwise I'd use RegistryKey.OpenRemoteBaseKey...although if anyone can 
tell me how to use this with a provided username/password, it would be 
great), I have usernames/passwords with administrator rights.  I was able to 
create a process remotely, so I know that access rights is not the problem.

Any help, alternative method, or pointer to a solution would be appreciated.

JJG

2. using wmi to get username in remote machine - VB.Net

3. Enumerating software application remote registry values using VB.NET

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 


4. Enumerating Remote registry key values using VB.NET - VB.Net

5. Remote Registry Access using VB.NET to enumerate Installed Software Applications

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 


6. SMS Database query using VB.NET with WMI Impersonation

7. Problem accessing HKEY_USERS on remote machine via WMI

8. Access Remote machine registry - VB.Net