2

Stack Overflow 上有关于操作系统版本的问题,但不是关于 Windows 名称的问题,我希望使用 Node.js 找出 Windows 名称。

我研究了很多模块,如、os和using等,发现这些有助于获取操作系统描述、进程环境等。我也能得到它是 Linux 或 Windows,即我正在使用哪个平台。platformgetosprocess

但是,我如何检查使用 Node.js 安装在我的系统上的是 Windows 7 还是 8?

kinect2在我的 Node.js 项目中使用模块,该模块在 Windows 8 上运行良好,但我希望在 Windows 7 上使用它。

我已经检查过 Kinect2 不能与 Windows 7 一起使用。

4

3 回答 3

12

使用os.release().

> os.release();
'10.0.18363'

在 Windows 上,结果的形式为major.minor.build

查阅此表(来源)以确定 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,请查阅此表(来源)以确定确切的版本:

 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
于 2017-07-05T02:11:08.990 回答
4

您可以使用 .从命令行中找到 Windows 版本ver。例如,在我的机器上:

>  ver

Microsoft Windows [Version 10.0.14393]

要从节点执行此操作,请使用以下child_process.execSync方法:

var versionString = require('child_process').execSync('ver').toString().trim()

整个.toString().trim()业务是因为命令的原始输出以 a 形式返回Buffer,开头和结尾都有换行符。

于 2017-03-01T06:31:01.157 回答
-1
var os = require('os');
console.log(os.type());

请参阅此链接以获取更多参考: https ://millermedeiros.github.io/mdoc/examples/node_api/doc/os.html

另一种选择可以是 npm 库:“平台”

看看这个:https ://www.npmjs.com/package/platform

于 2017-03-01T06:30:04.760 回答