private static void RunDiskPart(string action, string vdiskPath) { var scriptPath = Path.GetTempFileName(); using (var scriptStream = File.CreateText(scriptPath)) { scriptStream.WriteLine($"select vdisk file=\"{vdiskPath}\""); scriptStream.WriteLine($"{action} vdisk"); } ProcessUtility.Run("diskpart", $"/s {scriptPath}"); File.Delete(scriptPath); }
private Tuple <bool, string> CheckDisk() { var previousDrives = DriveInfo.GetDrives(); RunDiskPart("attach", VhdxPath); var newDrives = DriveInfo.GetDrives(); var mountedDrive = newDrives.FirstOrDefault(d => previousDrives.All(p => p.Name != d.Name)); bool success = true; string checkResult = null; if (mountedDrive != null) { var result = ProcessUtility.Run("chkdsk", mountedDrive.Name.TrimEnd('\\')); success = result.Item1 == 0; checkResult = result.Item2; } RunDiskPart("detach", VhdxPath); return(Tuple.Create(success, checkResult)); }