Skip to content
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

Deno.osRelease() in Windows #9862

Closed
moncefplastin07 opened this issue Mar 22, 2021 · 5 comments · Fixed by #16441
Closed

Deno.osRelease() in Windows #9862

moncefplastin07 opened this issue Mar 22, 2021 · 5 comments · Fixed by #16441
Assignees
Labels
bug Something isn't working correctly public API related to "Deno" namespace in JS upstream Changes in upstream are required to solve these issues windows Related to Windows platform

Comments

@moncefplastin07
Copy link

hi guys I think there is a problem extracting the OS version via the Deno.osRelease() method in Windows because when I run this code,

console.log(Deno.osRelease());

I get 6.2.9200 in the console even though I am using Windows 10

Deno: v1.8.1
Windows: 10.0.19042

@moncefplastin07 moncefplastin07 changed the title Demo.osRelease() in Windows Deno.osRelease() in Windows Mar 22, 2021
@kitsonk kitsonk added bug Something isn't working correctly public API related to "Deno" namespace in JS windows Related to Windows platform labels Mar 22, 2021
@littledivy
Copy link
Member

Deno.osRelease() uses sys-info crate which uses GetVersionExW in Windows.

And according to the documentation -

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases.

Deno needs to be a manifested application. See https://docs.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1

Solution is to use Deno.build wherever possible.

@moncefplastin07
Copy link
Author

Thanks for your interest .. I tried to suggest this code but I don't know if it works in a practical way

async function getWindowsVersion() {
    const procces = Deno.run({
        cmd: ["wmic", "os", "get", "Version", "/value"],
        stdout: "piped",
        stderr: "piped",
      });
      return new TextDecoder().decode(await procces.output()).split("=")[1].trim();
    
}

console.log(await getWindowsVersion())

based on Deno.run and wmic cli in windows os .. I know it's not a practical method, just a try 😁

@Spoonbender
Copy link
Contributor

@littledivy unfortunately, making deno a "manifested application" won't solve the issue: if deno is manifested for some version X of Windows, then GetVersionEx will always return the version number of the target Windows version specified in the manifest and not the actual Windows version.

@Spoonbender
Copy link
Contributor

Spoonbender commented Apr 1, 2021

Aside for a WMI-based option like @moncefplastin07 suggested, a few other options are:
1. GetProductInfo
2. RtlGetVersion
3. From registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
4. Check the version number of a system DLL like kernel32.dll
Source

But perhaps we should just post a bug at the sys-info crate...
Edit: there is one already: FillZpp/sys-info-rs#86

@littledivy
Copy link
Member

@Spoonbender Yup, using RtlGetVersion and falling back to GetVersionEx sounds good? It better aligns with Node's os.version https://nodejs.org/api/os.html#os_os_version
(Need to be done in sys-info)

@bartlomieju bartlomieju added the upstream Changes in upstream are required to solve these issues label Aug 4, 2021
@bartlomieju bartlomieju self-assigned this Oct 25, 2022
littledivy added a commit that referenced this issue Nov 2, 2022
Fixes #9862 

`loadavg`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | `sysinfo` | - |
| Windows | - | Returns `DEFAULT_LOADAVG`. There is no concept of
loadavg on Windows |
| macOS, BSD | `getloadavg` |
https://www.freebsd.org/cgi/man.cgi?query=getloadavg |

`os_release`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | `/proc/sys/kernel/osrelease` | - |
| Windows |
[`RtlGetVersion`](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlgetversion)
| dwMajorVersion . dwMinorVersion . dwBuildNumber |
| macOS | `sysctl([CTL_KERN, KERN_OSRELEASE])` | - |

`hostname`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Unix | `gethostname(sysconf(_SC_HOST_NAME_MAX))` | - |
| Windows | `GetHostNameW` | - |

`mem_info`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | sysinfo | - |
| Windows | `sysinfoapi::GlobalMemoryStatusEx` | - |
| macOS | <br> <pre> sysctl([CTL_HW, HW_MEMSIZE]); <br> sysctl([CTL_VM,
VM_SWAPUSAGE]); <br> host_statistics64(mach_host_self(), HOST_VM_INFO64)
</pre> | - |
DjDeveloperr pushed a commit to DjDeveloperr/deno that referenced this issue Nov 4, 2022
Fixes denoland#9862 

`loadavg`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | `sysinfo` | - |
| Windows | - | Returns `DEFAULT_LOADAVG`. There is no concept of
loadavg on Windows |
| macOS, BSD | `getloadavg` |
https://www.freebsd.org/cgi/man.cgi?query=getloadavg |

`os_release`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | `/proc/sys/kernel/osrelease` | - |
| Windows |
[`RtlGetVersion`](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlgetversion)
| dwMajorVersion . dwMinorVersion . dwBuildNumber |
| macOS | `sysctl([CTL_KERN, KERN_OSRELEASE])` | - |

`hostname`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Unix | `gethostname(sysconf(_SC_HOST_NAME_MAX))` | - |
| Windows | `GetHostNameW` | - |

`mem_info`

| Target family | Syscall | Description |
| ------------- | ------- | ----------- |
| Linux | sysinfo | - |
| Windows | `sysinfoapi::GlobalMemoryStatusEx` | - |
| macOS | <br> <pre> sysctl([CTL_HW, HW_MEMSIZE]); <br> sysctl([CTL_VM,
VM_SWAPUSAGE]); <br> host_statistics64(mach_host_self(), HOST_VM_INFO64)
</pre> | - |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly public API related to "Deno" namespace in JS upstream Changes in upstream are required to solve these issues windows Related to Windows platform
Projects
None yet
5 participants