Brauschi Ответов: 1

Прочитайте реестр с помощью WMI и используйте microsoft.management.infrastructure с помощью cimsession.


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"];
                }


Что я уже пробовал:

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

Dave Kreskowiak

Вы говорите об этом -> GitHub - PowerShell/MMI[^] (Microsoft.Management.Инфраструктура)?

Brauschi

Нет, речь идет о сборке преемника для управления системой.
Видишь ли https://docs.microsoft.com/de-de/windows/win32/wmisdk/connecting-to-wmi-remotely-with-c-?redirectedfrom=MSDN

1 Ответов

Рейтинг:
0

Brauschi

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();