Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }