如何使用 Node.js 获取 Windows 版本?
How to get Windows version using Node.js?
Stack Overflow 上有关于 OS 版本的问题,但没有关于 Windows 名称的问题,我希望使用 Node.js 找出 Windows 名称。
我研究了很多模块,如 os
、platform
、getos
和使用 process
等,发现这些有助于获取操作系统描述,过程环境等。我也能得到它是 Linux 或 Windows 即我正在使用哪个平台。
但是,我如何检查我的系统上使用 Node.js 安装的 Windows 7 还是 8?
我在我的 Node.js 项目中使用 kinect2
模块,它在 Windows 8 上运行良好,但我希望在 Windows 7 上使用它。
我已经检查过 Kinect2 不能与 Windows 7.
var os = require('os');
console.log(os.type());
请参阅此 link 以获取更多参考资料:
https://millermedeiros.github.io/mdoc/examples/node_api/doc/os.html
另一个选择可以是 npm 库:"platform"
您可以使用 ver
从命令行找到 Windows 版本。例如,在我的机器上:
> ver
Microsoft Windows [Version 10.0.14393]
要从节点执行此操作,请使用 child_process.execSync
方法:
var versionString = require('child_process').execSync('ver').toString().trim()
整个 .toString().trim()
业务是因为命令的原始输出作为 Buffer
返回,开头和结尾都有换行符。
使用os.release()
.
> os.release();
'10.0.18363'
在 Windows 上,结果的格式为 major.minor.build
参考这个 table (source) 来确定 Windows 的版本:
Version major.minor
------------------------------------------ -------------
Windows 10, Windows Server 2016 10.0
Windows 8.1, Windows Server 2012 R2 6.3
Windows 8, Windows Server 2012 6.2
Windows 7, Windows Server 2008 R2 6.1
Windows Vista, Windows Server 2008 6.0
Windows XP Professional x64 Edition, 5.2
Windows Server 2003, Windows Home Server
Windows XP 5.1
Windows 2000 5.0
对于 Windows 10 具体而言,请参阅此 table (source) 以确定确切的版本:
Version build
----------------- -------
Windows 10 1909 18363
Windows 10 1903 18362
Windows 10 1809 17763
Windows 10 1803 17134
Windows 10 1709 16299
Windows 10 1703 15063
Windows 10 1607 14393
Windows 10 1511 10586
Windows 10 1507 10240
Stack Overflow 上有关于 OS 版本的问题,但没有关于 Windows 名称的问题,我希望使用 Node.js 找出 Windows 名称。
我研究了很多模块,如 os
、platform
、getos
和使用 process
等,发现这些有助于获取操作系统描述,过程环境等。我也能得到它是 Linux 或 Windows 即我正在使用哪个平台。
但是,我如何检查我的系统上使用 Node.js 安装的 Windows 7 还是 8?
我在我的 Node.js 项目中使用 kinect2
模块,它在 Windows 8 上运行良好,但我希望在 Windows 7 上使用它。
我已经检查过 Kinect2 不能与 Windows 7.
var os = require('os');
console.log(os.type());
请参阅此 link 以获取更多参考资料: https://millermedeiros.github.io/mdoc/examples/node_api/doc/os.html
另一个选择可以是 npm 库:"platform"
您可以使用 ver
从命令行找到 Windows 版本。例如,在我的机器上:
> ver
Microsoft Windows [Version 10.0.14393]
要从节点执行此操作,请使用 child_process.execSync
方法:
var versionString = require('child_process').execSync('ver').toString().trim()
整个 .toString().trim()
业务是因为命令的原始输出作为 Buffer
返回,开头和结尾都有换行符。
使用os.release()
.
> os.release();
'10.0.18363'
在 Windows 上,结果的格式为 major.minor.build
参考这个 table (source) 来确定 Windows 的版本:
Version major.minor
------------------------------------------ -------------
Windows 10, Windows Server 2016 10.0
Windows 8.1, Windows Server 2012 R2 6.3
Windows 8, Windows Server 2012 6.2
Windows 7, Windows Server 2008 R2 6.1
Windows Vista, Windows Server 2008 6.0
Windows XP Professional x64 Edition, 5.2
Windows Server 2003, Windows Home Server
Windows XP 5.1
Windows 2000 5.0
对于 Windows 10 具体而言,请参阅此 table (source) 以确定确切的版本:
Version build
----------------- -------
Windows 10 1909 18363
Windows 10 1903 18362
Windows 10 1809 17763
Windows 10 1803 17134
Windows 10 1709 16299
Windows 10 1703 15063
Windows 10 1607 14393
Windows 10 1511 10586
Windows 10 1507 10240