Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code:


ManagementClass ObjManagementClassRegistry = new ManagementClass(_objPublicManagementScope, new ManagementPath("StdRegProv"), null);
                ManagementBaseObject inParams = ObjManagementClassRegistry.GetMethodParameters("GetStringValue");
                inParams["hDefKey"] = 0x80000002;// HKEY_LOCAL_MACHINE;
                inParams["sSubKeyName"] = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
                inParams["sValueName"] = "UBR";



                ManagementBaseObject ObjOutParams = ObjManagementClassRegistry.InvokeMethod("GetDWORDValue", inParams, null);

                if (Convert.ToUInt32(ObjOutParams["ReturnValue"]) == 0)
                {
                    var ddd = ObjOutParams["uValue"];
                }


What I have tried:

The problem I need to do is in the Microsoft.Management.Infrastructure assembly.

I want to read the Subversion remotely from the operating system. Remote Registry and Remote PowerShell are not allowed :-(


I want to thank you in advance for your help

Greetings Brauschi
Posted
Updated 13-May-20 9:50am
v2
Comments
Dave Kreskowiak 12-May-20 17:09pm    
Are you talking about this -> GitHub - PowerShell/MMI[^] (Microsoft.Management.Infrastructure)?
Brauschi 12-May-20 17:21pm    
No, it's about the successor assembly for system management.
See https://docs.microsoft.com/de-de/windows/win32/wmisdk/connecting-to-wmi-remotely-with-c-?redirectedfrom=MSDN

1 solution

C#
string strComputer = "ComputerName";
           string strUser = "UserName";
           string strPassword = "UserPassword";
           string strDomain = "DomainName";


           SecureString securepassword = new SecureString();
           foreach (char c in strPassword)
           {
               securepassword.AppendChar(c);
           }

           CimCredential Credentials = new CimCredential(PasswordAuthenticationMechanism.Kerberos, strDomain, strUser, securepassword);
           WSManSessionOptions SessionOptions = new WSManSessionOptions() { DestinationPort = 5985 };
           SessionOptions.AddDestinationCredentials(Credentials);
           CimSession SystemSession = CimSession.Create(strComputer, SessionOptions);
           bool Connected = SystemSession.TestConnection(out CimInstance TmpInstance, out CimException TmpExeption);



           // CLASSES_ROOT = 2147483648;
           // CURRENT_USER = 2147483649;
           // LOCAL_MACHINE = 2147483650;
           // USERS = 2147483651;
           // CURRENT_CONFIG = 2147483653;

           UInt32 RegRoot = 2147483650;

           CimMethodParametersCollection CimParams = new CimMethodParametersCollection();
           CimParams.Add(CimMethodParameter.Create("hDefKey", RegRoot, CimFlags.In));
           CimParams.Add(CimMethodParameter.Create("sSubKeyName", @"SOFTWARE\Microsoft\Windows NT\CurrentVersion", CimFlags.In));
           CimParams.Add(CimMethodParameter.Create("sValueName", "UBR", CimFlags.In));


           // GetStringValue = sValue
           // GetMultiStringValue = sValue
           // GetExpandedStringValue = sValue

           // GetDWORDValue = uValue
           // GetQWORDValue = uValue
           // GetBinaryValue = uValue

           CimMethodResult NameResults = SystemSession.InvokeMethod(new CimInstance("StdRegProv", @"root\default"), "GetDWORDValue", CimParams);

           string strUBR_RegistryValue = NameResults.OutParameters["uValue"].Value.ToString();
 
Share this answer
 

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