Advertisement
Guest User

WMI Client

a guest
Jul 19th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Management;
  3.  
  4. class TestProgram {
  5.     public static void Main(string[] args) {
  6.  
  7.         ConnectionOptions options = new ConnectionOptions();
  8.         options.Username = "Administrator";
  9.         options.Password = "dRum&5853";
  10.         options.Authentication = (AuthenticationLevel)Enum.Parse(typeof(AuthenticationLevel), "Packet");
  11.         options.Impersonation = (ImpersonationLevel)Enum.Parse(typeof(ImpersonationLevel), "Impersonate");
  12.         options.Authority = "ntlmdomain:WORKGROUP";
  13.  
  14.         ManagementScope scope = new ManagementScope( "\\\\10.129.12.234\\root\\cimv2", options );
  15.  
  16.         try {
  17.             scope.Connect();
  18.             Console.WriteLine("Connection successful.");
  19.         } catch (Exception e) {
  20.             Console.WriteLine("An exception has occured!!!\n");
  21.             Console.WriteLine(e.Message);
  22.             System.Environment.Exit(1);
  23.         }
  24.  
  25.         SelectQuery query = new SelectQuery( "Win32_PerfFormattedData_PerfDisk_LogicalDisk", "name IS NOT NULL" );
  26.         ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  27.  
  28.         try {
  29.             ManagementObjectCollection result = searcher.Get();
  30.  
  31.             foreach( ManagementBaseObject row in result ) {
  32.                 foreach( PropertyData property in row.Properties ) {
  33. //                  Console.WriteLine(property.Name + " = " + property.Value);
  34.                 }
  35.             }
  36.  
  37.         } catch (Exception e) {
  38.             Console.WriteLine("An exception has occured!!!\n");
  39.             Console.WriteLine(e.Message);
  40.             System.Environment.Exit(1);
  41.         }
  42.  
  43.         Main(null);
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement