469,613 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Code Sample To Change Remote Registry Key

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
Jan 9 '06 #1
2 12281
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
"scorpion53061" <sc************@nospamhereyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Jan 10 '06 #2
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

"scorpion53061" <sc************@nospamhereyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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

Jan 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by scorpion53061 | last post: by
16 posts views Thread by gumby | last post: by
4 posts views Thread by Chuck B | last post: by
3 posts views Thread by CAIBird | last post: by
7 posts views Thread by Mark Carrington | last post: by
8 posts views Thread by Hayato Iriumi | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.