Results 1 to 5 of 5

Thread: Reading registry of remote machine using WMI

  1. #1
    Join Date
    May 2008
    Posts
    10

    Reading registry of remote machine using WMI

    Hi,
    Is it possible to read registry of a remote machine using WMI in C#. I have written the following program to read the registry of a remote machine.But It gives exception as Access is denied.Please suggest me what needs to be changed.

    using System;
    using System.Management;
    using Microsoft.Win32;
    using System.Diagnostics;
    using System.IO;

    namespace SystemInfoCollectorinCS
    {
    /// <summary>
    /// CSC.cc.assay: This class collects system information of local machine.
    /// </summary>
    class SystemInfoCollectorinCS
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {

    try{

    ManagementScope managementScope;
    string regKeyToGet=null, keyToRead=null;
    string serverName="ip address of remote machine";
    string adminUser="userid";
    string adminUserPassword="paswword";

    ConnectionOptions connectionOptions = new ConnectionOptions();
    string wmiPath;
    if(serverName == null || serverName.Length == 0 || adminUser == null || adminUser.Length == 0 || adminUserPassword == null ||
    adminUserPassword.Length == 0)
    {
    //specify WMI path for local machine
    wmiPath = @"root\cimv2";
    }
    else
    {

    //set connection parameters for remote machine
    connectionOptions.Username = adminUser;
    connectionOptions.Password = adminUserPassword;
    //specify WMI path for remote machine
    Console.WriteLine("Setting the WMI path");
    wmiPath = String.Format(@"\\{0}\root\cimv2", serverName);
    Console.WriteLine("Setting the WMI path is done");

    }
    Console.WriteLine("Setting the connection");
    managementScope = new ManagementScope(wmiPath, connectionOptions);
    Console.WriteLine("Setting the connection is done");

    Console.WriteLine("Accessing the registry of remote");
    ManagementClass registry = new ManagementClass(managementScope, new ManagementPath("StdRegProv"), null);
    Console.WriteLine("Accessing the registry of remote machine is done");
    // Returns a specific value for a specified key
    Console.WriteLine("Returning a specific value for a specified key");
    ManagementBaseObject inParams = registry.GetMethodParameters("GetStringValue");
    Console.WriteLine("Returning a specific value for a specified key is done");

    inParams["sSubKeyName"] = regKeyToGet;
    inParams["sValueName"] = keyToRead;
    Console.WriteLine("Invokeing Method");

    ManagementBaseObject outParams = registry.InvokeMethod("GetStringValue", inParams, null);
    Console.WriteLine("Invokeing Method");

    Console.WriteLine(outParams["sValue"].ToString());


    }// try

    catch (Exception ex)
    {
    Console.WriteLine(ex.Message.ToString());
    //err = ex.Message.ToString();
    }


    }


    }
    }

  2. #2
    Join Date
    Apr 2008
    Posts
    49
    I suggest you can use RegistryKey.OpenRemoteBaseKey Method which opens a new RegistryKey that represents the requested key on a remote machine.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,465
    Check out the WMI Code Creator and use it on the Win32_Registry Class to generate code for you, you can select "Target computer" as Remote and select code language as C#.

  4. #4
    Join Date
    May 2008
    Posts
    10
    Thanks a lot to both of you..

  5. #5
    Join Date
    Mar 2012
    Posts
    1

    Re: Reading registry of remote machine using WMI

    Plz suggest me the complete code....i need to scan a remote computer registry from a local machine,though the local machine does not have admin rights bt credentials of remote machine i can provide....i have tried a lot many thing,if anyone is there who can help me out guys ??

Similar Threads

  1. Error reading registry key
    By Tarjan in forum Operating Systems
    Replies: 3
    Last Post: 17-11-2009, 08:21 PM
  2. Enable remote desktop registry
    By Matrix316 in forum Operating Systems
    Replies: 3
    Last Post: 07-11-2009, 10:25 AM
  3. OS level of a remote machine
    By GeforceUser in forum Networking & Security
    Replies: 5
    Last Post: 02-05-2009, 06:20 PM
  4. Is it possible to run any .exe in the remote machine using WMI?
    By Swati_here_2008 in forum Software Development
    Replies: 3
    Last Post: 05-05-2008, 06:45 PM
  5. WMI to remote machine
    By AndyS in forum Windows Server Help
    Replies: 3
    Last Post: 17-10-2007, 07:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,643,261,120.30372 seconds with 17 queries