Skip to content

feat(useragent): add Windows support for getUname() to get User-Agent. #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Thedarkmatter10
Copy link

@Thedarkmatter10 Thedarkmatter10 commented Apr 29, 2025

// TODO: if there is appetite for it in the community
// add support for Windows GetSystemInfo

I do have appetite for this! I’d be happy to extend the implementation to include GetSystemInfo or any additional support from the community as it becomes available or necessary.

Feature: Add Windows Support for getUname() in User Agent, similar to the existing Unix support.

This PR adds a Windows-specific implementation of the getUname() function to match the format and style used on Unix systems. It is designed to support consistent system identification for tools like Stripe CLI or other cross-platform utilities.


Summary

  • Implements getUname() for Windows systems.
  • Output matches Unix format:

Example:

OUTPUT "Windows DESKTOP-EGCRO4R 10.0.19045 Build 19045 x86_64

🔧 Technical Details

✅ Uses from x/sys/windows

  • windows.GetComputerName – gets the local hostname.
  • windows.UTF16ToString – converts UTF-16 output.

❗ Manually defined (not in x/sys/windows)

  • RtlGetVersion – for accurate OS version info (from ntdll.dll).
  • SYSTEM_INFO struct – to get CPU architecture via GetNativeSystemInfo.
  • Architecture constants like PROCESSOR_ARCHITECTURE_AMD64, ARM64, etc.

🧱 Reason for Manual Definitions

These Windows APIs/structs are currently not exposed by x/sys/windows as of 2025. This PR safely and clearly defines them using proper alignment and system docs.


🔒 Safety Notes

  • RtlGetVersion is the officially recommended way (by Microsoft) to get OS version, unlike GetVersionEx or syscall.GetVersion() which are deprecated or inaccurate post-Windows 8.1.
  • All manual structs align with Microsoft’s API layout (see sysinfoapi.h, winnt.h).

✅ Unit Test Included


TEST RESULT PHOTOS

I am using this on a Windows machine. Please find the attached photo for reference.

  1. System PROOF what i am using.

proof1

  1. Test result after executing the code :

testResult1

…le format

Adds Windows-specific implementation of getUname() to produce output similar to Unix uname.
Includes CPU architecture detection, OS version parsing, and hostname retrieval using x/sys/windows.
Maintains consistent return format for CLI and telemetry consistency.
@Thedarkmatter10 Thedarkmatter10 requested a review from a team as a code owner April 29, 2025 13:25
Copy link

cla-assistant bot commented Apr 29, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant