Remote Registry

2019-03-04 16:53发布

问题:

I know this has been talked about a few times about remote registry access, but I cannot find any good examples on how to implement this.

I did find http://www.codeproject.com/KB/cs/cpimpersonation1.aspx which seems to have code that will do what I want, however, this seems to be connecting to the same PC where the app is running from. What I want is to connect to remote PC in a different domain.

I have been doing some reading but cannot figure out how to modify this code to do so.

Any help would be appreciated on how to use the code to connect to a remote pc.

回答1:

You can start from this article: RegistryKey.OpenRemoteBaseKey. But you user account should be allowed to operate with registry on this remote machine! And impersonation is not the best way to resolve your task. LogonUser creates new security context on that machine where it is called. This means that user with permissions to access remote registry also should have permission to logon locally. This is very strong requirement.

I propose alternative solution: Before accessing registry you can use WNetAddConnection2 to create connection to IPC$ share on remote computer using credentials of user that have proper rights to access registry. Don't forget to cancel the connection when you finish your work with registry.