Code Sample To Change Remote Registry Key

S

scorpion53061

hi all,

I thought I would give this back and see if anyone could improve on it. I
was working with the remote registry class. This code opens the
ScreenSaverIsSecure registry setting and changes it to not require a
password prompt anymore.

One change that would be helpful is to somehow figure out how to include an
IP address where the server name is called. I suspect it is a syntax I am
missing. This morning I was running it from within teh network from other
machines so I could get away with it.



Imports System.Management
Imports System
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Security.Permissions
Imports Microsoft.Win32

Dim options As ConnectionOptions
options = New ConnectionOptions()
options.Impersonation = ImpersonationLevel.Impersonate
options.Username = "username"
options.Password = "password"

Dim scope As ManagementScope

scope = New ManagementScope("\\servername\root\cimv2", options)
scope.Options.EnablePrivileges = True
scope.Connect()
If scope.IsConnected = True Then
MsgBox("CONNECTED")
End If

Try
Dim environmentKey As RegistryKey
environmentKey = RegistryKey.OpenRemoteBaseKey( _
RegistryHive.CurrentUser,
"SERVERNAME").OpenSubKey("Control Panel\Desktop", True)

For Each valueName As String In
environmentKey.GetValueNames()
If valueName.ToString = "ScreenSaverIsSecure" Then
environmentKey.SetValue(valueName, "1")
Exit For
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
 
S

scorpion53061

One interesting result of this code was that no computer that was a member
of the domain would be allowed to reboot the server. Contstantly drew
security exceptions concerning the changing of the value in the registry on
the server. It did permit it to login.

However, machines not members of the domain but using the same connection on
the network were able to execute this code and reboot the server.

Again if anyone knows how to adjus the servername so that in can include an
IP address please advise.

Kelly
 
S

scorpion53061

The way to include an IP address when using WMI and requesting a connection
to the server is like this:

Dim scope As ManagementScope
scope = New ManagementScope("\\10.100.10.10\root\cimv2",
options)

Port 135 must be open and MSDTC must be enabled on the server. For those
reasons it I will only use this on a short term basis.

It does not appear to be possible however to run this application from a
member of the domain's computer regardless of how I impersonate the
Administrator. Again if anyone has ideas on how to make this happen I would
like to hear it.

If it runs from an outside machine where the user is the Administrator it
will reboot the system while using the public IP to connect. Otherwise if
you attempt this from a machine that is a member of the server's domain, it
will give you security exceptions about being not allowed to access the
registry.

This is my last post as no one else seems interested in this topic. It
obviously is timely for me.

Kelly
 

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

Top