Releases: solomonw1/WinFetch
Releases · solomonw1/WinFetch
Version 2 of WinFetch
There was a version 1 (it was never on GitHub).
There is a v2.0.0 binary here.
Here is the code v1.0.0:
// winfetch.cpp : This file contains the 'main' function. Program execution begins and ends there.s
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <Windows.h>
#include <stdlib.h>
#pragma comment(lib, "version.lib")
using namespace std;
// Required for RtlGetVersion()
#pragma comment(lib, "ntdll.lib")
string getEnvVar(const char* name) {
char* pValue;
size_t len;
errno_t err = _dupenv_s(&pValue, &len, name);
if (err) return "Error Getting variable - " + string(name);
return string(pValue);
}
extern "C" {
typedef LONG NTSTATUS, * PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)
// Windows 2000 and newer
NTSYSAPI NTSTATUS NTAPI RtlGetVersion(PRTL_OSVERSIONINFOEXW lpVersionInformation);
}
RTL_OSVERSIONINFOEXW getWindowsOSinformation() {
RTL_OSVERSIONINFOEXW osVers;
osVers.dwOSVersionInfoSize = sizeof(osVers);
// fill the structure with version details
NTSTATUS status = RtlGetVersion(&osVers);
// this should always succeed
assert(status == STATUS_SUCCESS);
return osVers;
}
string getWindowsVersionString() {
RTL_OSVERSIONINFOEXW osVers = getWindowsOSinformation();
if (osVers.dwMajorVersion == 6) {
if (osVers.dwMinorVersion == 0) {
return "Windows Vista";
} else if (osVers.dwMinorVersion == 1) {
return "Windows 7";
} else if (osVers.dwMinorVersion == 2) {
return "Windows 8";
} else if (osVers.dwMinorVersion == 3) {
return "Windows 8.1";
} else {
return "There was a problem evaluating the Windows version";
}
} if (osVers.dwMajorVersion == 10) {
if (osVers.dwBuildNumber >= 22000) {
return "Windows 11";
} else if (osVers.dwBuildNumber >= 21327) { // Earliest known Win11 Build
return "Pre Dev-Channel Windows 11";
} else {
return "Windows 10";
}
}
else {
return "Windows XP or earlier";
}
}
namespace SystemInformation {
void windowsVersion() {
string windowsVersionString = getWindowsVersionString();
RTL_OSVERSIONINFOEXW osVers = getWindowsOSinformation();
if (windowsVersionString == "Windows XP or earlier") {
cout << "Windows Version: " <<
getWindowsVersionString() <<
". Build is " <<
osVers.dwMajorVersion << "." <<
osVers.dwMinorVersion << "." <<
osVers.dwBuildNumber <<
endl;
}
else {
cout << "Windows Version: " <<
getWindowsVersionString() <<
endl;
}
}
void hardwareInformation() {
SYSTEM_INFO siSysInfo;
// Copy the hardware information to the SYSTEM_INFO structure.
GetSystemInfo(&siSysInfo);
// Display the contents of the SYSTEM_INFO structure.
cout << "Hardware information:" << endl;
cout << " OEM ID: " << siSysInfo.dwOemId << endl;
cout << " Number of processors: " << siSysInfo.dwNumberOfProcessors << endl;
cout << " Page size: " << siSysInfo.dwPageSize << endl;
cout << " Processor type: " << siSysInfo.dwProcessorType << endl;
cout << " Minimum application address: " << siSysInfo.lpMinimumApplicationAddress << endl;
cout << " Maximum application address: " << siSysInfo.lpMaximumApplicationAddress << endl;
cout << " Active processor mask: " << siSysInfo.dwActiveProcessorMask << endl;
}
void systemInformation() {
string data;
cout << "System information:" << endl;
data = getEnvVar("username");
cout << " Username: " << data << endl;
data = getEnvVar("windir");
cout << " Windows Directory: " << data << endl;
data = getEnvVar("path");
cout << " Path: " << data << endl;
data = getEnvVar("computername");
cout << " Computer Name: " << data << endl;
}
}
int main() {
SystemInformation::windowsVersion();
SystemInformation::hardwareInformation();
SystemInformation::systemInformation();
return 0;
}