Exemplo n.º 1
0
 public sealed override string ToString()
 {
     return("{ AC1: " + AC1.ToString("X") +
            ", AC2: " + AC2.ToString("X") +
            ", AC3: " + AC3.ToString("X") +
            ", AC4: " + AC4.ToString("X") +
            ", AC5: " + AC5.ToString("X") +
            ", AC6: " + AC6.ToString("X") +
            ", VB1: " + B1.ToString("X") +
            ", VB2: " + B2.ToString("X") +
            ", MB: " + MB.ToString("X") +
            ", MC: " + MC.ToString("X") +
            ", MD: " + MD.ToString("X") + " }");
 }
Exemplo n.º 2
0
        public static string GetFreeSpace(string drive)
        {
            double MB;
            string results = "Unknown Free Bytes";

            drive = drive.Replace("\\", "");
            long safeResults;
            long freeBytes  = 0;
            long totalBytes = 0;
            long totalFree  = 0;

            try
            {
                System.Management.ManagementObjectCollection myMOC;
                myMOC = new System.Management.ManagementObjectSearcher(new System.Management.SelectQuery("SELECT FreeSpace FROM Win32_LogicalDisk WHERE deviceID = '" + drive + "'")).Get();

                foreach (System.Management.ManagementObject myMO in myMOC)
                {
                    MB = ConvertUtil.cDbl(myMO.Properties["FreeSpace"].Value.ToString());
                    MB = MB / MEM_MB;
                    MB = Math.Floor(MB);

                    results = MB.ToString("n0") + " MB free.";

                    break;
                }
            }
            catch
            {
                try
                {
                    safeResults = GetDiskFreeSpaceEx(drive + "\\", ref freeBytes, ref totalBytes, ref totalFree);

                    if (safeResults != 0)
                    {
                        MB = freeBytes;
                        MB = MB / MEM_MB;
                        MB = Math.Floor(MB);

                        results = MB.ToString("n0") + " MB free.";
                    }
                }
                catch
                {
                }
            }

            return(results);
        }