Пример #1
0
        private void StartTree()
        {
            try
            {
                // Set a default icon for the Computer.
                Icon iconForFile = SystemIcons.WinLogo;
                Invoke((MethodInvoker) delegate { driveImageList.Images.Add(iconForFile); });

                Log.Debug("Create the root node.");
                TreeNode tvwRoot = new TreeNode {
                    Text = Environment.MachineName, ImageIndex = 0
                };
                tvwRoot.SelectedImageIndex = tvwRoot.ImageIndex;
                BeginInvoke((MethodInvoker) delegate { driveTree.Nodes.Add(tvwRoot); });

                Log.Debug("Now we need to add any children to the root node.");
                foreach (Win32DiskDrive deviceInfo in Win32DiskDrive.Retrieve())
                {
                    try
                    {
                        Invoke((MethodInvoker) delegate { FillInStorageDeviceDirectoryType(tvwRoot, deviceInfo); });
                    }
                    catch (Exception ex)
                    {
                        Log.Warn(ex, "A storage device failed to enumerate.");
                    }
                }

                BeginInvoke((MethodInvoker) delegate { tvwRoot.Expand(); });
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, @"StartTree Threw:");
            }
        }
Пример #2
0
        private void FillInStorageDeviceDirectoryType(TreeNode parentNode, Win32DiskDrive win32Disk)
        {
            TreeNode thisNode = new TreeNode
            {
                Text = win32Disk.Caption,
                Tag  = win32Disk
            };

            parentNode.Nodes.Add(thisNode);

            using RawDisk disk = new RawDisk(win32Disk.DeviceId);
            FillInStorageDeviceDirectoryType(thisNode, disk);

            var partitionQueryText =
                $"associators of {{{win32Disk.RelativePath}}} where AssocClass = Win32_DiskDriveToDiskPartition";

            var partitionQuery = new ManagementObjectSearcher(partitionQueryText);

            foreach (ManagementObject p in partitionQuery.Get())
            {
                var logicalDriveQueryText =
                    $"associators of {{{p.Path.RelativePath}}} where AssocClass = Win32_LogicalDiskToPartition";
                var logicalDriveQuery = new ManagementObjectSearcher(logicalDriveQueryText);
                foreach (ManagementObject ld in logicalDriveQuery.Get())
                {
                    Win32LogicalDisk ldp  = new Win32LogicalDisk(ld);
                    TreeNode         part = new TreeNode
                    {
                        Text = string.Concat(ldp.VolumeName, @" -> ", ldp.Caption),
                        Tag  = ldp
                    };

                    thisNode.Nodes.Add(part);
                }
            }
        }
Пример #3
0
 public IActionResult Drives()
 {
     return(Json(Win32DiskDrive.Retrieve()));
 }
Пример #4
0
        protected override void FillFloppyDriveInfo()
        {
            ManagementObjectCollection moc = this.GetAllInfo(this.WSql);

            foreach (ManagementObject mo in moc)
            {
                Win32DiskDrive csp = new Win32DiskDrive();
                if (mo != null)
                {
                    csp.Availability           = GetManagementObject <ushort>(mo, "Availability");
                    csp.BytesPerSector         = GetManagementObject <uint>(mo, "BytesPerSector");
                    csp.Capabilities           = GetManagementObject <ushort[]>(mo, "Capabilities");
                    csp.CapabilityDescriptions = GetManagementObject <string[]>(mo, "CapabilityDescriptions");
                    csp.Caption                 = GetManagementObject <string>(mo, "Caption");
                    csp.CompressionMethod       = GetManagementObject <string>(mo, "CompressionMethod");
                    csp.ConfigManagerErrorCode  = GetManagementObject <uint>(mo, "ConfigManagerErrorCode");
                    csp.ConfigManagerUserConfig = GetManagementObject <bool>(mo, "ConfigManagerUserConfig");
                    csp.CreationClassName       = GetManagementObject <string>(mo, "CreationClassName");
                    csp.DefaultBlockSize        = GetManagementObject <ulong>(mo, "DefaultBlockSize");
                    csp.Description             = GetManagementObject <string>(mo, "Description");
                    csp.DeviceID                = GetManagementObject <string>(mo, "DeviceID");
                    csp.ErrorCleared            = GetManagementObject <bool>(mo, "ErrorCleared");
                    csp.ErrorDescription        = GetManagementObject <string>(mo, "ErrorDescription");
                    csp.ErrorMethodology        = GetManagementObject <string>(mo, "ErrorMethodology");
                    csp.Index                       = GetManagementObject <uint>(mo, "Index");
                    csp.Cim_InstallDate             = GetManagementObject <string>(mo, "InstallDate");
                    csp.InterfaceType               = GetManagementObject <string>(mo, "InterfaceType");
                    csp.LastErrorCode               = GetManagementObject <uint>(mo, "LastErrorCode");
                    csp.Manufacturer                = GetManagementObject <string>(mo, "Manufacturer");
                    csp.MaxBlockSize                = GetManagementObject <ulong>(mo, "MaxBlockSize");
                    csp.MaxMediaSize                = GetManagementObject <ulong>(mo, "MaxMediaSize");
                    csp.MediaLoaded                 = GetManagementObject <bool>(mo, "MediaLoaded");
                    csp.MediaType                   = GetManagementObject <string>(mo, "MediaType");
                    csp.MinBlockSize                = GetManagementObject <ulong>(mo, "MinBlockSize");
                    csp.Model                       = GetManagementObject <string>(mo, "Model");
                    csp.Name                        = GetManagementObject <string>(mo, "Name");
                    csp.NeedsCleaning               = GetManagementObject <bool>(mo, "NeedsCleaning");
                    csp.NumberOfMediaSupported      = GetManagementObject <bool>(mo, "NumberOfMediaSupported");
                    csp.Partitions                  = GetManagementObject <uint>(mo, "Partitions");
                    csp.PNPDeviceID                 = GetManagementObject <string>(mo, "PNPDeviceID");
                    csp.PowerManagementCapabilities = GetManagementObject <ushort[]>(mo, "PowerManagementCapabilities");
                    csp.PowerManagementSupported    = GetManagementObject <bool>(mo, "PowerManagementSupported");
                    csp.SCSIBus                     = GetManagementObject <uint>(mo, "SCSIBus");
                    csp.SCSILogicalUnit             = GetManagementObject <ushort>(mo, "SCSILogicalUnit");
                    csp.SCSIPort                    = GetManagementObject <ushort>(mo, "SCSIPort");
                    csp.SCSITargetId                = GetManagementObject <ushort>(mo, "SCSITargetId");
                    csp.SectorsPerTrack             = GetManagementObject <uint>(mo, "SectorsPerTrack");
                    csp.Signature                   = GetManagementObject <uint>(mo, "Signature");
                    csp.Size                        = GetManagementObject <ulong>(mo, "Size");
                    csp.Status                      = GetManagementObject <string>(mo, "Status");
                    csp.StatusInfo                  = GetManagementObject <ushort>(mo, "StatusInfo");
                    csp.SystemCreationClassName     = GetManagementObject <string>(mo, "SystemCreationClassName");
                    csp.SystemName                  = GetManagementObject <string>(mo, "SystemName");
                    csp.TotalCylinders              = GetManagementObject <ulong>(mo, "TotalCylinders");
                    csp.TotalHeads                  = GetManagementObject <uint>(mo, "TotalHeads");
                    csp.TotalSectors                = GetManagementObject <ulong>(mo, "TotalSectors");
                    csp.TotalTracks                 = GetManagementObject <ulong>(mo, "TotalTracks");
                    csp.TracksPerCylinder           = GetManagementObject <uint>(mo, "TracksPerCylinder");

                    ps.Add(csp);
                }
            }
            moc.Dispose();
        }