tags:

views:

841

answers:

3

Hai every one I am developing an windows application in which i have to block the removable storage devices such as pendrives.I found that its possible by changing the registry value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor,start value to 4.But the problem is I have to block it on remote systems too.Can any one suggest me how to change the value of registry of remote system using c# with a code or sites where i can i find the code for this.

+1  A: 

The .net way is to use Microsoft.Win32.RegistryKey.OpenRemoteBaseKey.

An alternative would be to use WMI. There are lots of examples on Google for reading values; replacing GetStringValue with SetStringValue (or SetDWORDValue, etc.) should do what you want.

Heinzi
Or how about PowerShell? http://mybsinfo.blogspot.com/2007/01/powershell-remote-registry-and-you-part.html
rohancragg
A: 

You probably want to take a look at the Remote Registry Service and make an RPC call.

MSDN description: http://msdn.microsoft.com/en-us/library/aa940121%28WinEmbedded.5%29.aspx MSDN example using RegistryKey.OpenRemoteBaseKey: http://msdn.microsoft.com/en-us/library/8zha3xws.aspx

Michael Baker
A: 

You need to have Remote Registry service running on remote machine. Then you can use WMI to connect the registry. Here is a code sample script from this site:

Dim strComputer
Dim strUserName
Dim strPassword
Dim objLocator
Dim objService
Dim objRegistry

strComputer = "somesys" 
strUserName = "somename" 
strPassword = "somepw" 

Set objLocator = CreateObject("WbemScripting.SWbemLocator") 
Set objService = objLocator.ConnectServer( strComputer, _
"Root\Default", strUserName, strPassword ) 

objService.Security_.impersonationlevel = 3 

Set objRegistry = objService.Get( "StdRegProv" )

'Do something here like retrieving or setting values.

Set objRegistry = Nothing
Set objLocator = Nothing
Set objService = Nothing

you can get many valuable results by googling for "using WMI to modify remote registry"

TheVillageIdiot