how do I modify remote registeries using VB.NET (and COM+)



I am attempting to write a program to alter remote registeries. I am
familiar with VBScript and so I was using WMI to connect to remote machines.
How would I do this in VB.Net?

I got this far..

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btRDesktop.Click
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002

Dim myConnectionOptions As New System.Management.ConnectionOptions
With myConnectionOptions
..Impersonation = System.Management.ImpersonationLevel.Impersonate
'* Use next line for XP
..Authentication = System.Management.AuthenticationLevel.Packet
'* Use next line for Win prior XP
'*.Authentication = System.Management.AuthenticationLevel.Connect
End With
Dim myManagementScope As System.Management.ManagementScope
'* Replace the "." with an actual servername for remote connection
Dim myServerName As String = bxInputBox.Text
myManagementScope = New System.Management.ManagementScope("\\" & _
myServerName & "\root\cimv2:StdRegProv", myConnectionOptions)
'* connect to WMI namespace
If myManagementScope.IsConnected = False Then
bxOutputBox.AppendText("Could not connect to WMI namespace")
End If
Dim myObjectSearcher As System.Management.ManagementObjectSearcher
Dim myCollection As System.Management.ManagementObjectCollection
Dim myObject As System.Management.ManagementObject
Dim strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
Dim strValueName = "TrustPolicy"
'myObjectSearcher = New System.Management.ManagementObjectSearcher( _
' myManagementScope.Path.ToString, "Select * From Win32_Product")

'myObjectSearcher.Get(HKEY_LOCAL_MACHINE, strKeyPath, strValueName,
'bxOutputBox.AppendText("Current WSH Trust Policy Value: " & strValue)

End Sub
End Class

Rajesh Mishra [MSFT]

StdRegProv registry Provider class will do the trick for you. However I see
one problem wiht your connect string below

You currently have

change this to

Please look at the 2nd link below for examples


Key WMI Resources:
1> Official WMI FAQ from WMI Development Team:
2> Technet Scriptcenter Resource for lots of common system administration

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question