Update Registry or Environment Variable on Remote Machine in C#

Environment variable are available in “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment” in registry. By making a new entry in registry we can set environment variable on remote machine.
Here is the code to update the registry or set environment variable of the remote machine.

void UpdateRegistryOnRemotemachine(string RemoteMachineName)
        //retrieve Key information
        RegistryKey environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "\\\\" + RemoteMachineName).OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true);

        if (environmentKey != null)
            RegistryKey envRegistry = environmentKey;
            envRegistry.SetValue(txtVariableName.Text.Trim(), txtVariableValue.Text.Trim());
    catch (Exception Ex)
        string ErrorMsg = "\r\nError:\t" + Ex.Message;
        ErrorMsg += "\r\nStack:\t" + Ex.StackTrace;


To run above code successfully following settings must be done on remote machine –
1. “Remote Registry” service should be start on remote machine.
– To start “Remote Registry” service, type services.msc on run prompt and search for “Remote Registry”. Right click on “Remote Registry” service and set it to automatic and start it.

2. Window Firewall should be configure or should be off on remote machine.
3. A user (which will access registry of remote machine) must be added with administrator privileges on remote machine. To add user with administrator privileges do following thing
– Right click on MyComputer and click on manage.
– Expand Local users and groups
– Double click on groups and then double click on administrator group.
– Add user (which will access registry of remote machine from another machine) in this group.

Now by doing all above setting that user can update registry of remote machine.

Posted in Uncategorized. 3 Comments »

3 Responses to “Update Registry or Environment Variable on Remote Machine in C#”

  1. ver champions league gratis Says:

    That is a great tip particularly to those fresh to
    the blogosphere. Short but very accurate information… Many thanks for sharing this one.
    A must read article!

  2. Brigida Says:

    Greetings! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when browsing from my iphone. I’m trying to find a template or plugin
    that might be able to fix this issue. If you have any recommendations, please share.

  3. barknetwork.com Says:

    Tough disks and strong-state drives are utilized for internal storage.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: