Click here to Skip to main content
16,005,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
Doing
ManagementObject obj = new ManagementObject(@"root\default:StdRegProv");

throws ArgumentOutOfRangeException
as well as
ManagementClass regClass = new ManagementClass(new ManagementPath("StdRegProv"));
inParams= regClass.GetMethodParameters("GetStringValue"); //throws ManagementException "Not found"

What the..????????????
Posted

1 solution

If you're trying to do registry stuff on a remote system, you may not have sufficient privileges. I would break your code down into parts, all contained in a try/catch block.

Is there an inner exception?

BTW, I found this with google:

C#
public static string ConnectToRegistry (string servername)
{
    string regKeyToGet, keyToRead;
    ConnectionOptions oConn = new ConnectionOptions();
    oConn.Username = "admin";
    oConn.Password = "pass";
    ManagementScope scope = new ManagementScope(@"//" + servername + 
                                                @"/root/default", 
                                                oConn);
    registry = new ManagementClass(scope, 
                                   new ManagementPath("StdRegProv"), 
                                   null);

    // Returns a specific value for a specified key
    ManagementBaseObject inParams = registry.GetMethodParameters("GetStringValue");
    inParams["sSubKeyName"] = regKeyToGet;
    inParams["sValueName"] = keyToRead;
    ManagementBaseObject outParams = registry.InvokeMethod("GetStringValue", inParams, null);

    return outParams["sValue"].ToString();
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900