Skip to content

Commit cbeb474

Browse files
committed
reading drive details
1 parent a2e6029 commit cbeb474

File tree

12 files changed

+229
-5
lines changed

12 files changed

+229
-5
lines changed

PLP-SystemInfo.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.4.33213.308
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.1.11312.151 d18.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PLP-SystemInfo", "PLP-SystemInfo\PLP-SystemInfo.csproj", "{193C7457-B4BA-4120-9400-5F501F6573A0}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PLP_SystemInfoTest", "PLP_SystemInfoTest\PLP_SystemInfoTest.csproj", "{67F6C47C-DFE3-45D9-9537-FE8433451496}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemInfoTest", "SystemInfoTest\SystemInfoTest.csproj", "{918A665A-2996-4564-8D5F-7D59032E80A3}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{67F6C47C-DFE3-45D9-9537-FE8433451496}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{67F6C47C-DFE3-45D9-9537-FE8433451496}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{67F6C47C-DFE3-45D9-9537-FE8433451496}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{918A665A-2996-4564-8D5F-7D59032E80A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{918A665A-2996-4564-8D5F-7D59032E80A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{918A665A-2996-4564-8D5F-7D59032E80A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{918A665A-2996-4564-8D5F-7D59032E80A3}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using PLP_SystemInfo.Models;
2+
using System;
3+
using System.Linq;
4+
using System.Management;
5+
6+
public class DriveInfo
7+
{
8+
public static DriveDetails GetDriveHardwareInfo(string drivePath)
9+
{
10+
char driveLetter = char.ToUpper(drivePath.Trim().First(c => char.IsLetter(c)));
11+
12+
var scope = new ManagementScope(@"\\localhost\root\Microsoft\Windows\Storage");
13+
scope.Connect();
14+
15+
uint diskNumber = 0;
16+
bool found = false;
17+
var queryPartition = new ObjectQuery($"SELECT DiskNumber FROM MSFT_Partition WHERE DriveLetter = '{driveLetter}'");
18+
19+
using (var searcher = new ManagementObjectSearcher(scope, queryPartition))
20+
{
21+
var partitionObj = searcher.Get().Cast<ManagementObject>().FirstOrDefault();
22+
if (partitionObj != null)
23+
{
24+
diskNumber = (uint)partitionObj["DiskNumber"];
25+
found = true;
26+
}
27+
}
28+
29+
if (!found) throw new Exception("Partition für " + driveLetter + " nicht gefunden.");
30+
31+
var queryDisk = new ObjectQuery($"SELECT * FROM MSFT_PhysicalDisk WHERE DeviceId = '{diskNumber}'");
32+
33+
using (var searcher = new ManagementObjectSearcher(scope, queryDisk))
34+
{
35+
var diskObj = searcher.Get().Cast<ManagementObject>().FirstOrDefault();
36+
if (diskObj == null) throw new Exception("Physische Disk nicht gefunden.");
37+
38+
var result = new DriveDetails();
39+
result.PhysicalDiskId = diskObj["DeviceId"]?.ToString();
40+
result.Model = diskObj["FriendlyName"]?.ToString();
41+
result.MediaTypeRaw = Convert.ToInt32(diskObj["MediaType"]);
42+
result.BusTypeRaw = Convert.ToInt32(diskObj["BusType"]);
43+
44+
return result;
45+
}
46+
}
47+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace PLP_SystemInfo.Models
6+
{
7+
public class DriveDetails
8+
{
9+
public string PhysicalDiskId { get; set; }
10+
public string Model { get; set; }
11+
public int MediaTypeRaw { get; set; }
12+
public int BusTypeRaw { get; set; }
13+
14+
public bool IsSSD
15+
{
16+
get { return MediaTypeRaw == 4; }
17+
}
18+
19+
public string MediaType
20+
{
21+
get
22+
{
23+
switch (MediaTypeRaw)
24+
{
25+
case 3:
26+
return "HDD";
27+
case 4:
28+
return "SSD";
29+
case 5:
30+
return "SCM (Storage Class Memory)";
31+
case 0:
32+
return "Unspecified (Oft USB/Virtuell)";
33+
default:
34+
return "Unbekannt (" + MediaTypeRaw + ")";
35+
}
36+
}
37+
}
38+
39+
public string BusType
40+
{
41+
get
42+
{
43+
switch (BusTypeRaw)
44+
{
45+
case 7:
46+
return "USB";
47+
case 8:
48+
return "RAID";
49+
case 11:
50+
return "SATA";
51+
case 17:
52+
return "NVMe";
53+
default:
54+
return "Andere (" + BusTypeRaw + ")";
55+
}
56+
}
57+
}
58+
}
59+
}

PLP-SystemInfo/PLP-SystemInfo.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@
1212
<RepositoryUrl>https://github.com/ProgrammerLP/PLP-SystemInfo</RepositoryUrl>
1313
<PackageTags>info, system, system-info, system info, windows</PackageTags>
1414
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
15-
<AssemblyVersion>2.1.0</AssemblyVersion>
16-
<FileVersion>2.1.0</FileVersion>
17-
<Version>2.1.0</Version>
15+
<AssemblyVersion>2.2.0</AssemblyVersion>
16+
<FileVersion>2.2.0</FileVersion>
17+
<Version>2.2.0</Version>
1818
<Copyright>© - ProgrammerLP</Copyright>
1919
<PackageProjectUrl>https://github.com/ProgrammerLP/PLP-SystemInfo</PackageProjectUrl>
2020
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<PackageReleaseNotes>- reading drive details</PackageReleaseNotes>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
25+
<DebugType>portable</DebugType>
26+
</PropertyGroup>
27+
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
29+
<DebugType>portable</DebugType>
2130
</PropertyGroup>
2231

2332
<ItemGroup>

PLP_SystemInfoTest/MainWindow.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using PLP_SystemInfo;
22
using PLP_SystemInfo.ComponentInfo;
3+
using PLP_SystemInfo.Models;
34
using System.Windows;
45

56
namespace PLP_SystemInfoTest
@@ -50,6 +51,27 @@ public MainWindow()
5051
list.Items.Add(RamInfo.GetAvailableRam());
5152
list.Items.Add(RamInfo.GetRamInUse());
5253
list.Items.Add(RamInfo.GetHardwareReservedRam());
54+
55+
DriveDetails info = DriveInfo.GetDriveHardwareInfo("C");
56+
list.Items.Add("Drive C:");
57+
list.Items.Add($"Physische Disk ID: {info.PhysicalDiskId}");
58+
list.Items.Add($"Modell Name: {info.Model}");
59+
list.Items.Add($"Medien-Typ: Code: {info.MediaType}");
60+
list.Items.Add($"Bus-Typ: {info.BusType}");
61+
62+
DriveDetails info2 = DriveInfo.GetDriveHardwareInfo("D");
63+
list.Items.Add("Drive D:");
64+
list.Items.Add($"Physische Disk ID: {info2.PhysicalDiskId}");
65+
list.Items.Add($"Modell Name: {info2.Model}");
66+
list.Items.Add($"Medien-Typ: Code: {info2.MediaType}");
67+
list.Items.Add($"Bus-Typ: {info2.BusType}");
68+
69+
DriveDetails info3 = DriveInfo.GetDriveHardwareInfo("E");
70+
list.Items.Add("Drive E:");
71+
list.Items.Add($"Physische Disk ID: {info3.PhysicalDiskId}");
72+
list.Items.Add($"Modell Name: {info3.Model}");
73+
list.Items.Add($"Medien-Typ: Code: {info3.MediaType}");
74+
list.Items.Add($"Bus-Typ: {info3.BusType}");
5375
}
5476
}
5577
}

PLP_SystemInfoTest/PLP_SystemInfoTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<UseWPF>true</UseWPF>
9+
<StartupObject>PLP_SystemInfoTest.App</StartupObject>
910
</PropertyGroup>
1011

1112
<ItemGroup>

SystemInfoTest/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="SystemInfoTest.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:SystemInfoTest"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

SystemInfoTest/App.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace SystemInfoTest
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}

SystemInfoTest/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

SystemInfoTest/MainWindow.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Window x:Class="SystemInfoTest.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:SystemInfoTest"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<Grid>
10+
<ListView x:Name="list" />
11+
</Grid>
12+
</Window>

0 commit comments

Comments
 (0)