Guest User

Untitled

a guest
Apr 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. uint LOCAL_MACHINE = 0x80000002;
  2. string results = "";
  3. ConnectionOptions options = new ConnectionOptions();
  4. options.Impersonation = ImpersonationLevel.Impersonate;
  5. options.EnablePrivileges = true;
  6. options.Username = this.txtUser.Text;
  7. options.Password = this.txtPassword.Text;
  8.  
  9. ManagementScope myScope = new ManagementScope("\\" + this.txtMachine.Text + "\root\default", options);
  10. ManagementPath mypath = new ManagementPath("StdRegProv");
  11. ManagementClass mc = new ManagementClass(myScope, mypath, null);
  12.  
  13. ManagementBaseObject inParams = mc.GetMethodParameters("EnumKey");
  14. inParams["hDefKey"] = LOCAL_MACHINE;
  15. inParams["sSubKeyName"] = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall";
  16.  
  17. ManagementNamedValueCollection objCtx = new ManagementNamedValueCollection();
  18. objCtx.Add("__ProviderArchitecture", 64);
  19. objCtx.Add("__RequiredArchitecture", true);
  20.  
  21.  
  22. InvokeMethodOptions invokeOptions = new InvokeMethodOptions();
  23. invokeOptions.Context = objCtx;
  24. ManagementBaseObject outParams = mc.InvokeMethod("EnumKey", inParams, invokeOptions);
  25.  
  26. inParams = mc.GetMethodParameters("GetStringValue");
  27. inParams["hDefKey"] = LOCAL_MACHINE;
  28.  
  29. foreach(string name in (string[])outParams["sNames"])
  30. {
  31. inParams["sSubKeyName"] = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall" + "\" + name;
  32. inParams["sValueName"] = "DisplayName";
  33. outParams = mc.InvokeMethod("GetStringValue", inParams, invokeOptions);
  34.  
  35. if (!string.IsNullOrEmpty(((string)outParams["sValue"])))
  36. {
  37. results += outParams["sValue"] + "t";
  38. }
  39. }
  40.  
  41. myScope.Options.Context.Add("__ProviderArchitecture", 64);
  42. myScope.Options.Context.Add("__RequiredArchitecture", true);
Add Comment
Please, Sign In to add comment