Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Management;
- public static class Program
- {
- public static void Main()
- {
- const string username = @"DomainUser";
- const string password = @"Password";
- const string server = @"Server";
- const string query = @"Associators of {"
- + @"Win32_Directory.Name='"
- + @"c:program files (x86)a_test}"
- + @"'} "
- + @"Where AssocClass = Win32_Subdirectory ResultRole = PartComponent";
- var options = new ConnectionOptions { Username = username, Password = password };
- var wmiScope = new ManagementScope(@"\" + server + @"rootcimv2", options);
- var wmiQuery = new ObjectQuery(query);
- var searcher = new ManagementObjectSearcher(wmiScope, wmiQuery);
- var searchResults = searcher.Get();
- foreach (var searchResult in searchResults)
- {
- var subPath = searchResult.GetPropertyValue("Name").ToString();
- var system = Convert.ToBoolean(searchResult.GetPropertyValue("System"));
- Console.WriteLine($"subPath = {subPath}; system = {system}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement