Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint LOCAL_MACHINE = 0x80000002;
- string results = "";
- ConnectionOptions options = new ConnectionOptions();
- options.Impersonation = ImpersonationLevel.Impersonate;
- options.EnablePrivileges = true;
- options.Username = this.txtUser.Text;
- options.Password = this.txtPassword.Text;
- ManagementScope myScope = new ManagementScope("\\" + this.txtMachine.Text + "\root\default", options);
- ManagementPath mypath = new ManagementPath("StdRegProv");
- ManagementClass mc = new ManagementClass(myScope, mypath, null);
- ManagementBaseObject inParams = mc.GetMethodParameters("EnumKey");
- inParams["hDefKey"] = LOCAL_MACHINE;
- inParams["sSubKeyName"] = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall";
- ManagementNamedValueCollection objCtx = new ManagementNamedValueCollection();
- objCtx.Add("__ProviderArchitecture", 64);
- objCtx.Add("__RequiredArchitecture", true);
- InvokeMethodOptions invokeOptions = new InvokeMethodOptions();
- invokeOptions.Context = objCtx;
- ManagementBaseObject outParams = mc.InvokeMethod("EnumKey", inParams, invokeOptions);
- inParams = mc.GetMethodParameters("GetStringValue");
- inParams["hDefKey"] = LOCAL_MACHINE;
- foreach(string name in (string[])outParams["sNames"])
- {
- inParams["sSubKeyName"] = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall" + "\" + name;
- inParams["sValueName"] = "DisplayName";
- outParams = mc.InvokeMethod("GetStringValue", inParams, invokeOptions);
- if (!string.IsNullOrEmpty(((string)outParams["sValue"])))
- {
- results += outParams["sValue"] + "t";
- }
- }
- myScope.Options.Context.Add("__ProviderArchitecture", 64);
- myScope.Options.Context.Add("__RequiredArchitecture", true);
Add Comment
Please, Sign In to add comment