Cmd.cs 921 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Diagnostics;
  3. namespace Mtp2Dav.Utilities
  4. {
  5. internal static class Cmd
  6. {
  7. public static int Execute(string cmd, string args)
  8. {
  9. Console.WriteLine($">{cmd} {args}");
  10. var p = new Process
  11. {
  12. StartInfo =
  13. {
  14. FileName = cmd,
  15. Arguments = args,
  16. UseShellExecute = false,
  17. CreateNoWindow = false,
  18. }
  19. };
  20. p.Start();
  21. p.WaitForExit();
  22. return p.ExitCode;
  23. }
  24. public static int NetUse(string driveLetter, string unc)
  25. {
  26. return Execute("net", $"use {driveLetter}: {unc}");
  27. }
  28. public static int NetUseDriveLetterDelete(string driveLetter)
  29. {
  30. return Execute("net", $"use {driveLetter}: /d /y");
  31. }
  32. }
  33. }