728x90
반응형
안녕하세요
C#에서 레지스트리 항목을 조회하여 PC 윈도우 버전 및
메모리 정보, 디스크 정보 등을 조회 하는 코드를 포스팅하겠습니다.
1. 레지스트리 HKEY_LOCAL_MACHINE 하위 항목 조회
- using Microsoft.Win32;
private static string HKLM_GetString(string path, string key)
{
try
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(path);
if (rk == null) return "";
return (string)rk.GetValue(key);
}
catch { return ""; }
}
2. 레지스트리 항목을 조회하여 윈도우 버전 확인
public static string GetSystemVersion()
{
string ProductName = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName");
if (ProductName != "")
{
return ProductName;
}
return "";
}
3. 컴퓨터 메모리 정보 불러오기
- using Microsoft.VisualBasic.Devices;
- ComputerInfo - 컴퓨터의 메모리, 로드된 어셈블리, 이름 및 운영체제에 대한 정보를 가져오기 위한 속성을 제공
- TotalPhysicalMemory - 컴퓨터에 있는 실제 메모리의 전체 양을 가져옵니다.
public static string GetMemoryInfo()
{
ComputerInfo computerInfo = new ComputerInfo();
ulong memory = ulong.Parse(computerInfo.TotalPhysicalMemory.ToString());
return $"{memory / (1024 * 1024)} MB";
// return $"{memory / (1024 * 1024 * 1024)} GB";
}
4. 컴퓨터 디스크 드라이브 정보 불러오기
- using System.IO;
- DriveInfo.GetDrives - 컴퓨터에 있는 모든 논리 드라이브 이름을 검색합니다.
- VolumeLabel - 드라이브의 볼륨 레이블을 가져오간 설정합니다.
- TotalFreeSpace - 드라이브의 사용 가능한 공간 합계를 가져옵니다.(반환 값은 바이트 단위)
- TotalSize - 드라이브에 있는 저장소 공간의 크기 합계를 가져 옵니다.(반환값은 바이트 단위)
public static string GetDiskDriveInfo()
{
string ret = string.Empty;
DriveInfo[] driveInfo = DriveInfo.GetDrives();
foreach (var drive in driveInfo)
{
ret += $"{drive.VolumeLabel}:{drive.TotalFreeSpace}(of {drive.TotalSize})";
}
return ret;
}
728x90
반응형
'소소한 C# 지식' 카테고리의 다른 글
[C#] POST 방식으로 Web API 호출하기 (12) | 2022.05.12 |
---|---|
[C#] C#에서 비밀번호 검증(Password Validation) (22) | 2022.05.10 |
[C#]Local PC IP 조회 및 네트워크 상태 체크 (12) | 2022.05.03 |
[C#]C# Winform Datagridview Row 이동 하기 (2) | 2022.04.28 |
[C#]C# 기상청 API 연동하여 날씨 데이터 저장하기 (16) | 2022.04.26 |
댓글