Guest User

Untitled

a guest
Nov 6th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. string computer = "Computer_B";
  2. string domain = "WORKGROUP";
  3. string username = ".\LocalAdminUserName";
  4. string plaintextpassword;
  5.  
  6. Console.WriteLine("Enter password:");
  7. plaintextpassword = Console.ReadLine();
  8.  
  9. SecureString securepassword = new SecureString();
  10. foreach (char c in plaintextpassword)
  11. {
  12. securepassword.AppendChar(c);
  13. }
  14.  
  15. CimCredential Credentials = new
  16. CimCredential(PasswordAuthenticationMechanism.Default, domain,
  17. username,securepassword);
  18.  
  19. WSManSessionOptions SessionOptions = new WSManSessionOptions();
  20. SessionOptions.AddDestinationCredentials(Credentials);
  21.  
  22. CimSession Session = CimSession.Create(computer, SessionOptions);
  23.  
  24. var allVolumes = Session.QueryInstances(@"rootcimv2", "WQL", "SELECT * FROM Win32_LogicalDisk");
  25.  
  26. // Loop through all volumes
  27. foreach (CimInstance oneVolume in allVolumes)
  28. {
  29. Console.Writeline(oneVolume.CimInstanceProperties["SystemName"].Value.ToString());
  30. }
Add Comment
Please, Sign In to add comment