如何使用Node.js获取Windows版本?

有关于堆栈溢出操作系统版本的问题,但不是关于Windows名称,我正在寻找使用Node.js找出Windows名称。

我研究了osplatformgetos和using process等很多模块,发现这些模块对于获取操作系统描述,进程环境等都有帮助。我能够得到它是Linux还是Windows,也就是说我是哪个平台使用。

但是,我怎样才能检查,是我的系统上使用Node.js安装的Windows 7或8?

我在我的Node.js项目中使用kinect2模块,它在Windows 8上工作正常,但我期待在Windows 7上使用它。

我已经检查过,Kinect2不能在Windows 7上运行。

您可以使用ver从命令行findWindows版本。 例如,在我的机器上:

 > ver Microsoft Windows [Version 10.0.14393] 

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

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

整个.toString().trim()业务是因为该命令的原始输出以Buffer返回,在开始和结束处都有换行符。

使用os.release() 。 在Windows上, Node C ++代码将调用GetVersionEx()

os.release()的结果将采用以下格式:

 ${dwMajorVersion}.${dwMinorVersion}.${dwBuildNumber} 

请参阅此表( 从这里复制)来确定Windows的版本。

  Operating system dwMajorVersion dwMinorVersion ------------------------ ---------------- ---------------- Windows 10 10 0 Windows Server 2016 10 0 Windows 8.1 6 3 Windows Server 2012 R2 6 3 Windows 8 6 2 Windows Server 2012 6 2 Windows 7 6 1 Windows Server 2008 R2 6 1 Windows Server 2008 6 0 Windows Vista 6 0 Windows Server 2003 R2 5 2 Windows Server 2003 5 2 Windows XP 5 1 Windows 2000 5 0 
 var os = require('os'); console.log(os.type()); 

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

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

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