By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

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

P: n/a
I am attempting to write a VB.net 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
myManagementScope.Connect()
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,
strValue)
'bxOutputBox.AppendText("Current WSH Trust Policy Value: " & strValue)

End Sub
End Class
================================================== ======

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


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

You currently have
root\cimv2:StdRegProv

change this to
root\default:StdRegProv

Please look at the 2nd link below for examples

--
Thanks,
Rajesh

Key WMI Resources:
1> Official WMI FAQ from WMI Development Team:
http://www.microsoft.com/technet/scr...es/wmifaq.mspx
2> Technet Scriptcenter Resource for lots of common system administration
problems:
http://www.microsoft.com/technet/scr...r/default.mspx

"james" <ja*******@hotmail.com> wrote in message
news:eD****************@tk2msftngp13.phx.gbl...
I am attempting to write a VB.net 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
myManagementScope.Connect()
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,
strValue)
'bxOutputBox.AppendText("Current WSH Trust Policy Value: " & strValue)

End Sub
End Class
================================================== ======

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.