简体   繁体   中英

How to change the registry value of remote system using C#

我正在开发一个Windows应用程序,其中我必须阻止可移动存储设备(例如pendrives)。我发现通过更改HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services \\ UsbStor的注册表值,将其初始值设置为4可以实现此目的。问题是我也必须在远程系统上阻止它。有人可以建议我如何使用带有代码或我可以在其中找到代码的站点的c#更改远程系统的注册表值。

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.

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(WinEmbedded.5).aspx MSDN example using RegistryKey.OpenRemoteBaseKey: http://msdn.microsoft.com/en-us/library/8zha3xws.aspx

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM