Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Management;
  4.  
  5. // This example demonstrates how to connect to remote machine
  6. // using supplied credentials.
  7. class Sample_ConnectionOptions
  8. {
  9. public int Main(string[] args)
  10. {
  11. ConnectionOptions options = new ConnectionOptions();
  12. options.Username = UserName; //could be in domain\user format
  13. options.Password = SecurelyStoredPassword;
  14. ManagementScope scope = new ManagementScope(
  15. "\\\\servername\\root\\cimv2",
  16. options);
  17. try
  18. {
  19. scope.Connect();
  20. ManagementObject disk = new ManagementObject(
  21. scope,
  22. new ManagementPath("Win32_logicaldisk='c:'"),
  23. null);
  24. disk.Get();
  25. }
  26. catch (Exception e)
  27. {
  28. Console.WriteLine("Failed to connect: " + e.Message);
  29. }
  30. return 0;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement