Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using System;
  2. using System.Management;
  3.  
  4. public static class Program
  5. {
  6. public static void Main()
  7. {
  8. const string username = @"DomainUser";
  9. const string password = @"Password";
  10. const string server = @"Server";
  11.  
  12. const string query = @"Associators of {"
  13. + @"Win32_Directory.Name='"
  14. + @"c:program files (x86){a_test}"
  15. + @"'} "
  16. + @"Where AssocClass = Win32_Subdirectory ResultRole = PartComponent";
  17.  
  18. var options = new ConnectionOptions { Username = username, Password = password };
  19. var wmiScope = new ManagementScope(@"\" + server + @"rootcimv2", options);
  20. var wmiQuery = new ObjectQuery(query);
  21. var searcher = new ManagementObjectSearcher(wmiScope, wmiQuery);
  22. var searchResults = searcher.Get();
  23.  
  24. foreach (var searchResult in searchResults)
  25. {
  26. var subPath = searchResult.GetPropertyValue("Name").ToString();
  27. var system = Convert.ToBoolean(searchResult.GetPropertyValue("System"));
  28. Console.WriteLine($"subPath = {subPath}; system = {system}");
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement