コード例 #1
0
        public async Task <IActionResult> PutLogicalDisk([FromRoute] int id, [FromBody] LogicalDisk logicalDisk)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != logicalDisk.Id)
            {
                return(BadRequest());
            }

            _context.Entry(logicalDisk).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LogicalDiskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: radtek/disktools
        private void PrintLogicalDiskInformation(String deviceName)
        {
            using (var logicalDisk = new LogicalDisk(deviceName, true))
            {
                Console.WriteLine("Logical disk {0}", logicalDisk.DeviceName);

                logicalDisk.ReadDiskInformation();

                PrintPartitionInformation(logicalDisk.PartitionInformation);
                PrintVolumeBootRecord(logicalDisk.VolumeBootRecord);
            }
        }
コード例 #3
0
        public async Task <IActionResult> PostLogicalDisk([FromBody] LogicalDisk logicalDisk)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.LogicalDisks.Add(logicalDisk);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLogicalDisk", new { id = logicalDisk.Id }, logicalDisk));
        }
コード例 #4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            LogicalDisk = await _context.LogicalDisks.SingleOrDefaultAsync(m => m.Id == id);

            if (LogicalDisk == null)
            {
                return(NotFound());
            }
            return(Page());
        }
コード例 #5
0
 public LogicalDiskViewModel(LogicalDisk logicalDisk)
 {
     Caption            = logicalDisk.VolumeName + "(" + logicalDisk.Caption + ")";
     DeviceId           = logicalDisk.DeviceId;
     FileSystem         = logicalDisk.FileSystem;
     Type               = logicalDisk.Type;
     FreeSpace          = MemoryDisplayFormatter.Format(logicalDisk.FreeSpace);
     Size               = MemoryDisplayFormatter.Format(logicalDisk.Size);
     VolumeName         = logicalDisk.VolumeName;
     VolumeSerialNumber = logicalDisk.VolumeSerialNumber;
     FreeSpaceInt       = logicalDisk.FreeSpace;
     TakenSpaceInt      = logicalDisk.Size - logicalDisk.FreeSpace;
     SizeInt            = logicalDisk.Size;
     MemoryAllocation   = MemoryDisplayFormatter.Format((logicalDisk.Size - logicalDisk.FreeSpace)) +
                          " / " + MemoryDisplayFormatter.Format(logicalDisk.Size);
 }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            LogicalDisk = await _context.LogicalDisks.FindAsync(id);

            if (LogicalDisk != null)
            {
                _context.LogicalDisks.Remove(LogicalDisk);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
        public static string GetPCUniqueCode()
        {
            ManagementObjectSearcher CPUs         = new ManagementObjectSearcher("select * from Win32_Processor");
            ManagementObjectSearcher MotherBoards = new ManagementObjectSearcher("select * from Win32_BaseBoard");
            ManagementObjectSearcher LogicalDisks = new ManagementObjectSearcher("select * from Win32_LogicalDisk");
            string str = "";

            foreach (var CPU in CPUs.Get())
            {
                str += (string)CPU.GetPropertyValue("ProcessorID");
            }
            foreach (var MotherBoard in MotherBoards.Get())
            {
                str += (string)MotherBoard.GetPropertyValue("SerialNumber");
            }
            foreach (var LogicalDisk in LogicalDisks.Get())
            {
                str += (string)LogicalDisk.GetPropertyValue("VolumeSerialNumber");
            }
            return(GetHashString(str));
        }
コード例 #8
0
ファイル: OSInfoTo.cs プロジェクト: WuJiBase/np
        /// <summary>
        /// 可视化输出
        /// </summary>
        /// <returns></returns>
        public string ToView()
        {
            var dic = new Dictionary <int, string>
            {
                { 0, "" },
                { 1, $" 🎨 框架: {FrameworkDescription}" },
                { 2, $" 🔵 开机: {Math.Round(TickCount*1.0/1000/24/3600,2)} 天" },
                { 3, $" 🌟 系统: {(OperatingSystem ?? OS)}{(Is64BitOperatingSystem ? " ,64Bit" : "")}" },
                { 4, $" 📌 内核: {OSVersion.VersionString}" },
                { 5, $" 😳 用户: {UserName}" },
                { 6, $" 📊  CPU: {ProcessorName} ,{ProcessorCount} Core{ProgressBar(Convert.ToInt64(ProcessorUsage*100), 10000, false)}" },
                { 7, $" 📀 内存: {ProgressBar(TotalPhysicalMemory-FreePhysicalMemory,TotalPhysicalMemory)}" }
            };

            if (SwapTotal > 0)
            {
                dic.Add(8, $" 💿 Swap: {ProgressBar(SwapTotal - SwapFree, SwapTotal)}");
            }

            var lgds    = LogicalDisk.ToJson().ToJArray();
            var listlgd = new List <string>();

            for (int i = 0; i < lgds.Count; i++)
            {
                var lgdi = lgds[i];
                var fs   = Convert.ToInt64(lgdi["FreeSpace"].ToString());
                var size = Convert.ToInt64(lgdi["Size"].ToString());
                var name = lgdi["Name"].ToString();
                listlgd.Add(ProgressBar(size - fs, size, true, name));
            }
            dic.Add(9, $" 💿 磁盘: {string.Join(" ", listlgd)}");

            //排序
            var list = dic.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value).Values.ToList();

            return(string.Join("\r\n\r\n", list));
        }
コード例 #9
0
        //Loads up the drives information
        private static void LoadDriveInformation(string driveLetter)
        {
            //Clear out the structs
            ldisk     = default(LogicalDisk);
            currSpace = default(Space);
            dDrive    = default(DiskDrive);

            //Make sure drive letter is formatted as ex: "C:"
            driveLetter = driveLetter.Substring(0, 2);

            //New driveQuery to new ManagementObjectSearcher("Select * from Win32_DiskDrive")
            using (var driveQuery = new ManagementObjectSearcher("select * from Win32_LogicalDisk where DeviceID = '" + driveLetter + "'"))
            {
                //Foreach loop to go through the managementObjects in driveQuery
                try
                {
                    //Break on Load USB Detection Disconnected Context Error
                    //Need to get drive here

                    foreach (ManagementObject d in driveQuery.Get())
                    {
                        #region Load Data Structs
                        //Get the information from the LogicalDisk and DiskDrive classes on Windows
                        //LogicalDisk
                        ldisk.driveName       = Convert.ToString(d.Properties["Name"].Value);                      // C:
                        ldisk.driveCompressed = Convert.ToBoolean(d.Properties["Compressed"].Value);
                        ldisk.driveType       = Convert.ToUInt32(d.Properties["DriveType"].Value);                 // C: - 3
                        ldisk.fileSystem      = Convert.ToString(d.Properties["FileSystem"].Value);                // NTFS
                        //Calculate Space
                        currSpace.freeSpace  = ConversionToGig(Convert.ToUInt64(d.Properties["FreeSpace"].Value)); //converted to gigs
                        currSpace.totalSpace = ConversionToGig(Convert.ToUInt64(d.Properties["Size"].Value));      //converted to gigs
                        currSpace.usedSpace  = currSpace.totalSpace - currSpace.freeSpace;                         //Calculate usedSpace
                        //End Calculate space-----
                        dDrive.driveMediaType = Convert.ToUInt32(d.Properties["MediaType"].Value);                 // c: 12
                        dDrive.volumeName     = Convert.ToString(d.Properties["VolumeName"].Value);                // System
                        dDrive.volumeSerial   = Convert.ToString(d.Properties["VolumeSerialNumber"].Value);        // 12345678

                        //New Query to associate Win32_DiskDrive to DiskPartition
                        var partitionQueryText = string.Format("associators of {{{0}}} where AssocClass = Win32_LogicalDiskToPartition", d.Path.RelativePath);
                        //Create a new managementObjectSearcher giving it the query
                        var partitionQuery = new ManagementObjectSearcher(partitionQueryText);
                        //Loop to Search the ManagementObjects in the query
                        foreach (ManagementObject p in partitionQuery.Get())
                        {
                            string diskNum      = p.Properties["Name"].Value.ToString().Substring(6, 1);
                            string physicalName = string.Format("PHYSICALDRIVE" + diskNum);

                            //Create a new managementObjectSearcher giving it the query
                            var diskDriveQuery = new ManagementObjectSearcher("Select * from Win32_DiskDrive where Name like'%" + physicalName + "'");
                            //Loop to Search the ManagementObjects in the query
                            foreach (ManagementObject dd in diskDriveQuery.Get())
                            {
                                //DiiskDrive
                                dDrive.driveStatus  = Convert.ToString(dd.Properties["Status"].Value);            //Disk Status
                                dDrive.physicalName = Convert.ToString(dd.Properties["Name"].Value);              // \\.\PHYSICALDRIVE2
                                                                                                                  //diskName = Convert.ToString(d.Properties["Caption"].Value); // WDC WD5001AALS-xxxxxx
                                dDrive.diskManufacturer = Convert.ToString(dd.Properties["Manufacturer"].Value);
                                dDrive.diskModel        = Convert.ToString(dd.Properties["Model"].Value);         // WDC WD5001AALS-xxxxxx
                                dDrive.diskInterface    = Convert.ToString(dd.Properties["InterfaceType"].Value); // IDE
                                dDrive.mediaLoaded      = Convert.ToBoolean(dd.Properties["MediaLoaded"].Value);  // bool
                                dDrive.mediaType        = Convert.ToString(dd.Properties["MediaType"].Value);     // Fixed hard disk media
                                dDrive.mediaSignature   = Convert.ToUInt32(dd.Properties["Signature"].Value);     // int32
                                dDrive.mediaStatus      = Convert.ToString(dd.Properties["Status"].Value);        // OK
                            }//Logical Disk to Partition
                        }//DiskDrive to Partition
                        #endregion
                    }//Disk Drive
                }
                catch (Exception ex)
                {
                    //MessageBox.Show
                }
            }
        }
コード例 #10
0
ファイル: Application.cs プロジェクト: radtek/disktools
        protected override Int32 Execute()
        {
            try
            {
                if (1 == _commandLineParser.FileNames.Length)
                {
                    var deviceName = _commandLineParser.FileNames[0];

                    if (deviceName.EndsWith(":"))
                    {
                        PrintLogicalDiskInformation(deviceName);
                    }
                    else
                    {
                        PrintPhysicalDiskInformation(deviceName);
                    }
                }
                else if (_commandLineParser.IsOptionSet("p"))
                {
                    if (_commandLineParser.OptionHasValue("p"))
                    {
                        var deviceName = _commandLineParser.GetOptionString("p");

                        if (deviceName.Equals("all", StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (var deviceName1 in PhysicalDisk.GetDeviceNames())
                            {
                                PrintPhysicalDiskInformation(deviceName1);
                            }
                        }
                        else
                        {
                            UInt32 diskNumber;
                            if (UInt32.TryParse(deviceName, out diskNumber))
                            {
                                deviceName = PhysicalDisk.FormatDeviceName(diskNumber);
                            }

                            PrintPhysicalDiskInformation(deviceName);
                        }
                    }
                    else
                    {
                        PrintArray(PhysicalDisk.GetDeviceNames());
                    }
                }
                else if (_commandLineParser.IsOptionSet("l"))
                {
                    if (_commandLineParser.OptionHasValue("l"))
                    {
                        var deviceName = _commandLineParser.GetOptionString("l");

                        if (deviceName.Equals("all", StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (var deviceName1 in LogicalDisk.GetDeviceNames())
                            {
                                PrintLogicalDiskInformation(deviceName1);
                            }
                        }
                        else
                        {
                            if (1 == deviceName.Length)
                            {
                                var volume = Char.ToUpper(deviceName[0]);
                                if ((volume >= 'A') && (volume <= 'Z'))
                                {
                                    deviceName = LogicalDisk.FormatDeviceName(volume);
                                }
                            }

                            PrintLogicalDiskInformation(deviceName);
                        }
                    }
                    else
                    {
                        PrintArray(LogicalDisk.GetDeviceNames());
                    }
                }
                else
                {
                    Help();
                }

                return(0);
            }
            catch (Exception ex)
            {
                Print("Error reading disk information: {0}", ex.Message);
                return(1);
            }
        }
コード例 #11
0
ファイル: Application.cs プロジェクト: radtek/disktools
 private void PrintPartitionInformation(Kernel32.PARTITION_INFORMATION partitionInformation)
 {
     Console.WriteLine("\nPARTITION_INFORMATION:");
     Console.WriteLine("StartingOffset:\t\t{0:N0}", partitionInformation.StartingOffset);
     Console.WriteLine("PartitionLength:\t{0:N0}", partitionInformation.PartitionLength);
     Console.WriteLine("HiddenSectors:\t\t{0:N0}", partitionInformation.HiddenSectors);
     Console.WriteLine("PartitionNumber:\t{0}", partitionInformation.PartitionNumber);
     Console.WriteLine("PartitionType:\t\t0x{0:X2} ({1})", partitionInformation.PartitionType, LogicalDisk.GetPartitionTypeString(partitionInformation.PartitionType));
     Console.WriteLine("BootIndicator:\t\t{0}", partitionInformation.BootIndicator);
     Console.WriteLine("RecognizedPartition:\t{0}", partitionInformation.RecognizedPartition);
     Console.WriteLine("RewritePartition:\t{0}", partitionInformation.RewritePartition);
 }
コード例 #12
0
        /// <summary>
        /// Gets the computer system information
        /// </summary>
        /// <returns>The information about the computer system</returns>
        public ComputerSystem GetComputerSystem()
        {
            ComputerSystem computerSystem = new ComputerSystem();

            try
            {
                ManagementObjectSearcher   mos = new ManagementObjectSearcher(_OPERATING_SYSTEM_SEARCH_STRING);
                ManagementObjectCollection moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    computerSystem.BuildNumber = Convert.ToString(mo["BuildNumber"]);
                    //convert to bytes from kilobytes
                    computerSystem.FreePhysicalMemory = Convert.ToUInt64(mo["FreePhysicalMemory"]) * 1024;
                    computerSystem.FreeVirtualMemory  = Convert.ToUInt64(mo["FreeVirtualMemory"]) * 1024;

                    computerSystem.Caption                 = Convert.ToString(mo["Caption"]);
                    computerSystem.NumberOfUsers           = Convert.ToUInt32(mo["NumberOfUsers"]);
                    computerSystem.ServicePackMajorVersion = Convert.ToUInt16(mo["ServicePackMajorVersion"]);
                    computerSystem.ServicePackMinorVersion = Convert.ToUInt16(mo["ServicePackMinorVersion"]);
                    computerSystem.Version                 = Convert.ToString(mo["Version"]);
                    computerSystem.InstallDate             = ManagementDateTimeConverter.ToDateTime(Convert.ToString(mo["InstallDate"]));
                    computerSystem.LastBootUpTime          = ManagementDateTimeConverter.ToDateTime(Convert.ToString(mo["LastBootUpTime"]));
                }

                mos.Query.QueryString = _COMPUTER_SYSTEM_INFORMATION_SEARCH_STRING;
                moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    CPUInfo cpui = new CPUInfo();

                    cpui.NumberOfCores             = Convert.ToInt32(mo["NumberOfCores"]);
                    cpui.NumberOfLogicalProcessors = Convert.ToInt32(mo["NumberOfLogicalProcessors"]);
                    cpui.AddressWidth      = Convert.ToUInt16(mo["AddressWidth"]);
                    cpui.Caption           = Convert.ToString(mo["Caption"]);
                    cpui.CurrentClockSpeed = Convert.ToUInt32(mo["CurrentClockSpeed"]);
                    cpui.DeviceId          = Convert.ToString(mo["DeviceId"]);
                    cpui.ExtClock          = Convert.ToUInt32(mo["ExtClock"]);
                    cpui.L2CacheSize       = Convert.ToUInt32(mo["L2CacheSize"]);
                    cpui.L2CacheSpeed      = Convert.ToUInt32(mo["L2CacheSpeed"]);
                    cpui.L3CacheSize       = Convert.ToUInt32(mo["L3CacheSize"]);
                    cpui.L3CacheSpeed      = Convert.ToUInt32(mo["L3CacheSpeed"]);
                    cpui.Manufacturer      = Convert.ToString(mo["Manufacturer"]);
                    cpui.Name              = Convert.ToString(mo["Name"]);
                    cpui.ProcessorId       = Convert.ToString(mo["ProcessorId"]);
                    cpui.SocketDesignation = Convert.ToString(mo["SocketDesignation"]);
                    computerSystem.CpuInfo = cpui;
                }

                mos.Query.QueryString = _PHYSICAL_MEMORY_SEARCH_STRING;
                moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    PhysicalMemory pm = new PhysicalMemory();
                    pm.Capacity      = Convert.ToUInt64(mo["Capacity"]);
                    pm.Speed         = Convert.ToUInt32(mo["Speed"]);
                    pm.DeviceLocator = Convert.ToString(mo["DeviceLocator"]);

                    UInt16 memType = Convert.ToUInt16(mo["MemoryType"]);

                    if (_MEMORY_TYPE_DICTIONARY.ContainsKey(memType))
                    {
                        pm.MemoryType = _MEMORY_TYPE_DICTIONARY[memType];
                    }

                    pm.BankLabel  = Convert.ToString(mo["BankLabel"]);
                    pm.PartNumber = Convert.ToString(mo["PartNumber"]);
                    pm.DataWidth  = Convert.ToUInt16(mo["DataWidth"]);
                    pm.Tag        = Convert.ToString(mo["Tag"]);
                    computerSystem.PhysicalMemoryCollection.Add(pm);
                }

                mos.Query.QueryString = _COMPUTER_SYSTEM_SEARCH_STRING;
                moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    computerSystem.DnsHostName = Convert.ToString(mo["DNSHostName"]);
                    computerSystem.Domain      = Convert.ToString(mo["Domain"]);
                    UInt16 domainRoleId = Convert.ToUInt16(mo["DomainRole"]);

                    // Decode the id to string (based on online documentation)
                    switch (domainRoleId)
                    {
                    case (0):
                    {
                        computerSystem.DomainRole = "Standalone Workstation";
                        break;
                    }

                    case (1):
                    {
                        computerSystem.DomainRole = "Member Workstation";
                        break;
                    }

                    case (2):
                    {
                        computerSystem.DomainRole = "Standalone Server";
                        break;
                    }

                    case (3):
                    {
                        computerSystem.DomainRole = "Member Server";
                        break;
                    }

                    case (4):
                    {
                        computerSystem.DomainRole = "Backup Domain Controller";
                        break;
                    }

                    case (5):
                    {
                        computerSystem.DomainRole = "Primary Domain Controller";
                        break;
                    }
                    }
                    computerSystem.Manufacturer   = Convert.ToString(mo["Manufacturer"]);
                    computerSystem.Model          = Convert.ToString(mo["Model"]);
                    computerSystem.IsPartOfDomain = Convert.ToBoolean(mo["PartOfDomain"]);
                    computerSystem.Workgroup      = Convert.ToString(mo["Workgroup"]);
                }

                mos.Query.QueryString = _DISK_DRIVE_TO_PARTITION_SEARCH_STRING;
                moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    ManagementPath drivePath =
                        new ManagementPath(mo["Antecedent"].ToString());
                    ManagementPath partPath =
                        new ManagementPath(mo["Dependent"].ToString());

                    if (partPath.ClassName == "Win32_DiskPartition" && drivePath.ClassName == "Win32_DiskDrive")
                    {
                        ManagementObject pa = new ManagementObject(partPath);
                        ManagementObject dr = new ManagementObject(drivePath);

                        DiskDrive dd = new DiskDrive();
                        dd.DeviceId = Convert.ToString(dr["DeviceID"]);

                        if (!computerSystem.DiskDriveCollection.Contains(dd))
                        {
                            dd.Availability   = Convert.ToString(dr["Availability"]);
                            dd.BytesPerSector = Convert.ToUInt32(dr["BytesPerSector"]);

                            UInt16[] capabilities           = (UInt16[])dr["Capabilities"];
                            string[] capabilityDescriptions = (string[])dr["CapabilityDescriptions"];

                            for (int i = 0; i < capabilities.Length; i++)
                            {
                                if (_DISK_CAPABILITY_DICTIONARY.ContainsKey(capabilities[i]))
                                {
                                    dd.CapabilityDescriptionDictionary.Add(_DISK_CAPABILITY_DICTIONARY[capabilities[i]], capabilityDescriptions[i]);
                                }
                            }

                            dd.Caption = Convert.ToString(dr["Caption"]);

                            UInt32 configManagerErrorCode = Convert.ToUInt32(dr["ConfigManagerErrorCode"]);

                            if (_DISK_CONFIG_MANAGER_ERROR_CODE_DICTIONARY.ContainsKey(configManagerErrorCode))
                            {
                                dd.ConfigManagerErrorCode = _DISK_CONFIG_MANAGER_ERROR_CODE_DICTIONARY[configManagerErrorCode];
                            }

                            dd.DefaultBlockSize = Convert.ToUInt64(dr["DefaultBlockSize"]);
                            dd.DoesNeedCleaning = Convert.ToBoolean(dr["NeedsCleaning"]);
                            dd.ErrorDescription = Convert.ToString(dr["ErrorDescription"]);
                            dd.ErrorMethodology = Convert.ToString(dr["ErrorMethodology"]);
                            dd.InterfaceType    = Convert.ToString(dr["InterfaceType"]);
                            dd.IsMediaLoaded    = Convert.ToBoolean(dr["MediaLoaded"]);
                            dd.Manufacturer     = Convert.ToString(dr["Manufacturer"]);
                            dd.MaxBlockSize     = Convert.ToUInt64(dr["MaxBlockSize"]);
                            dd.MediaType        = Convert.ToString(dr["MediaType"]);
                            dd.MinBlockSize     = Convert.ToUInt64(dr["MinBlockSize"]);
                            dd.Model            = Convert.ToString(dr["Model"]);
                            dd.Name             = Convert.ToString(dr["Name"]);
                            dd.PartitionCount   = Convert.ToUInt32(dr["Partitions"]);
                            dd.PnpDeviceID      = Convert.ToString(dr["PNPDeviceID"]);

                            dd.IsPowerManagementSupported = Convert.ToBoolean(dr["PowerManagementSupported"]);
                            if (dd.IsPowerManagementSupported)
                            {
                                UInt16[] powerManagementCapabilities = (UInt16[])dr["PowerManagementCapabilities"];
                                foreach (UInt16 capability in powerManagementCapabilities)
                                {
                                    if (_DISK_POWER_CAPABILITIES_DICTIONARY.ContainsKey(capability))
                                    {
                                        dd.PowerManagementCapabilities.Add(_DISK_POWER_CAPABILITIES_DICTIONARY[capability]);
                                    }
                                }
                            }

                            dd.SerialNumber      = Convert.ToString(dr["SerialNumber"]);
                            dd.Signature         = Convert.ToUInt32(dr["Signature"]);
                            dd.Size              = Convert.ToUInt64(dr["Size"]);
                            dd.Status            = Convert.ToString(dr["Status"]);
                            dd.TotalCylinders    = Convert.ToUInt64(dr["TotalCylinders"]);
                            dd.TotalHeads        = Convert.ToUInt32(dr["TotalHeads"]);
                            dd.TotalSectors      = Convert.ToUInt64(dr["TotalSectors"]);
                            dd.TotalTracks       = Convert.ToUInt64(dr["TotalTracks"]);
                            dd.TracksPerCylinder = Convert.ToUInt32(dr["TracksPerCylinder"]);

                            computerSystem.DiskDriveCollection.Add(dd);
                        }

                        DiskPartition dp = new DiskPartition();
                        dp.BlockCount        = Convert.ToUInt64(pa["NumberOfBlocks"]);
                        dp.BlockSize         = Convert.ToUInt64(pa["BlockSize"]);
                        dp.Caption           = Convert.ToString(pa["Caption"]);
                        dp.HiddenSectorCount = Convert.ToUInt32(pa["HiddenSectors"]);
                        dp.Index             = Convert.ToUInt32(pa["Index"]);
                        dp.IsBootable        = Convert.ToBoolean(pa["Bootable"]);
                        dp.IsBootPartition   = Convert.ToBoolean(pa["BootPartition"]);
                        dp.Purpose           = Convert.ToString(pa["Purpose"]);
                        dp.Size           = Convert.ToUInt64(pa["Size"]);
                        dp.StartingOffset = Convert.ToUInt64(pa["StartingOffset"]);
                        dp.Type           = Convert.ToString(pa["Type"]);
                        dp.DeviceId       = Convert.ToString(pa["DeviceID"]);
                        dp.Name           = Convert.ToString(pa["Name"]);

                        foreach (DiskDrive drive in computerSystem.DiskDriveCollection)
                        {
                            if (drive.DeviceId.Equals(dd.DeviceId))
                            {
                                drive.DiskPartitions.Add(dp);
                            }
                        }
                    }
                }

                mos.Query.QueryString = _LOGICAL_DISK_TO_PARTITION_SEARCH_STRING;
                moc = mos.Get();

                foreach (ManagementObject mo in moc)
                {
                    ManagementPath partPath =
                        new ManagementPath(mo["Antecedent"].ToString());
                    ManagementPath logicalDiskPath =
                        new ManagementPath(mo["Dependent"].ToString());

                    if (partPath.ClassName == "Win32_DiskPartition" && logicalDiskPath.ClassName == "Win32_LogicalDisk")
                    {
                        ManagementObject ppmo = new ManagementObject(partPath);
                        ManagementObject ldmo = new ManagementObject(logicalDiskPath);

                        string partitionId = Convert.ToString(ppmo["DeviceID"]);

                        foreach (DiskDrive drive in computerSystem.DiskDriveCollection)
                        {
                            foreach (DiskPartition partition in drive.DiskPartitions)
                            {
                                if (partition.DeviceId.Equals(partitionId))
                                {
                                    LogicalDisk ld = new LogicalDisk();
                                    ld.Caption    = Convert.ToString(ldmo["Caption"]);
                                    ld.DeviceId   = Convert.ToString(ldmo["DeviceID"]);
                                    ld.FileSystem = Convert.ToString(ldmo["FileSystem"]);
                                    ld.FreeSpace  = Convert.ToUInt64(ldmo["FreeSpace"]);
                                    ld.Size       = Convert.ToUInt64(ldmo["Size"]);
                                    UInt32 driveTypeId = Convert.ToUInt32(ldmo["DriveType"]);

                                    if (_DRIVE_TYPE_DICTIONARY.ContainsKey(driveTypeId))
                                    {
                                        ld.Type = _DRIVE_TYPE_DICTIONARY[driveTypeId];
                                    }

                                    ld.VolumeName         = Convert.ToString(ldmo["VolumeName"]);
                                    ld.VolumeSerialNumber = Convert.ToString(ldmo["VolumeSerialNumber"]);

                                    partition.LogicalDisks.Add(ld);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                MyDebugger.Instance.LogMessage(exc, DebugVerbocity.Exception);
            }
            return(computerSystem);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            int ordered = 0;
            int brief   = 0;
            int netOnly = 0;
            int hdOnly  = 0;

            if (args.Length == 0)
            {
                Console.WriteLine("arguments:\n\t" +
                                  "-o #: get assigned instance\n\t" +
                                  "-b: brief\n\t-n: network adapter only\n\t" +
                                  "-d: disk only\n\t-a: all\n\t" +
                                  "-h: this usage\n");
            }
            else
            {
                foreach (String arg in args)
                {
                    switch (arg)
                    {
                    case "-o": ordered = 1; break;

                    case "-b": brief = 1; break;

                    case "-n":
                        netOnly = 1;
                        hdOnly  = 0;
                        break;

                    case "-d":
                        hdOnly  = 1;
                        netOnly = 0;
                        break;

                    case "-a":
                        hdOnly  = 0;
                        netOnly = 0;
                        ordered = 0;
                        break;

                    case "-h":
                        Console.WriteLine("arguments:\n\t" +
                                          "-o #: get assigned instance\n\t" +
                                          "-b: brief\n\t-n: network adapter only\n\t" +
                                          "-d: disk only\n\t-a: all\n\t" +
                                          "-h: this usage\n");
                        Environment.Exit(0);
                        break;

                    default:
                        if (ordered > 0 && !Int32.TryParse(arg, out ordered))
                        {
                            ordered = 0;
                        }
                        break;
                    }
                }
            }

            //BIOS biosOB;
            //OS osOB;
            //Serial[] serial;
            NetworkAdapter[] networkAdapterOB;
            LogicalDisk[]    hdOB;

            //biosOB = WMIHelper.WMIHelper.FillBiosInformation(Environment.MachineName, "", "", "Win32_BIOS");
            //osOB = WMIHelper.WMIHelper.FillOSInformation(Environment.MachineName, "", "", "Win32_OperatingSystem");
            networkAdapterOB = WMIHelper.WMIHelper.FillNetworkAdapter(Environment.MachineName, "", "", "Win32_NetworkAdapterConfiguration");
            hdOB             = WMIHelper.WMIHelper.FillLogicalDisks(Environment.MachineName, "", "", "Win32_LogicalDIsk");
            //serial = WMIHelper.WMIHelper.FillSerial(Environment.MachineName, "", "", "Win32_PnPEntity", "CP210x");
            //for (int i = 0; i < serial.Count(); ++i)
            //    Console.WriteLine("{0}: {1}", serial[i].port, serial[i].Description);
            //Console.WriteLine("BIOS # {0}", biosOB.SerialNumber);
            //Console.WriteLine("OS # {0}", osOB.SerialNumber);
            if (hdOnly == 0)
            {
                for (int i = 0; i < networkAdapterOB.Count(); ++i)
                {
                    NetworkAdapter na = networkAdapterOB[i];
                    if (na.MACAddress.Length > 0)
                    {
                        if (ordered > 1)
                        {
                            ordered--;
                        }
                        else
                        {
                            if (brief == 1)
                            {
                                Console.WriteLine("{0}", na.MACAddress);
                            }
                            else
                            {
                                Console.WriteLine("{0} # Network Interface({1})", na.MACAddress, na.Description);
                            }
                            if (ordered == 1)
                            {
                                netOnly = 1;
                                break;
                            }
                        }
                    }
                }
            }
            if (netOnly == 0)
            {
                for (int i = 0; i < hdOB.Count(); ++i)
                {
                    LogicalDisk ld = hdOB[i];
                    if (ld.VolumeSerialNumber.Length > 0)
                    {
                        if (ordered > 1)
                        {
                            ordered--;
                        }
                        else
                        {
                            if (brief == 1)
                            {
                                Console.WriteLine("{0}", ld.VolumeSerialNumber);
                            }
                            else
                            {
                                Console.WriteLine("{0} # Harddisk({1})", ld.VolumeSerialNumber, ld.Name);
                            }
                            if (ordered == 1)
                            {
                                netOnly = 1;
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #14
0
 public virtual void Show(LogicalDisk disk, Folder isDetailed)
 {
 }
コード例 #15
0
ファイル: TreeUserInterface.cs プロジェクト: Dakosia/CSharp
 public override void Show(LogicalDisk disk, Folder isDetailed)
 {
 }