DeleteFolderWithAdminRights.cs 665 B

123456789101112131415161718192021222324
  1. using System.Diagnostics;
  2. namespace NewArchivesCenter
  3. {
  4. internal class DeleteFolderWithAdminRights
  5. {
  6. public static void DeleteFolder(string folderPath)
  7. {
  8. string command = $"/c rmdir /s /q \"{folderPath}\"";
  9. ProcessStartInfo psi = new ProcessStartInfo
  10. {
  11. FileName = "cmd.exe",
  12. Arguments = command,
  13. Verb = "runas",
  14. UseShellExecute = true,
  15. WindowStyle = ProcessWindowStyle.Hidden
  16. };
  17. using (Process p = Process.Start(psi))
  18. {
  19. p.WaitForExit();
  20. }
  21. }
  22. }
  23. }