[英]How to get Windows version using Node.js?
Stack Overflow 上有關於操作系統版本的問題,但與 Windows 名稱無關,我希望使用 Node.js 找出 Windows 名稱。
我研究了很多模塊,如os
、 platform
、 getos
和 using process
等,發現這些模塊有助於獲取操作系統描述、進程環境等。我也能得到它是 Linux 或 Windows,即我是哪個平台使用。
但是,我如何檢查使用 Node.js 安裝在我的系統上的 Windows 7 還是 Windows 8?
我在 Node.js 項目中使用kinect2
模塊,該模塊在 Windows 8 上運行良好,但我希望在 Windows 7 上使用它。
我已經檢查過 Kinect2 不適用於 Windows 7。
使用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
您可以使用ver
從命令行查找 Windows 版本。 例如,在我的機器上:
> ver
Microsoft Windows [Version 10.0.14393]
要從節點執行此操作,請使用child_process.execSync
方法:
var versionString = require('child_process').execSync('ver').toString().trim()
整個.toString().trim()
業務是因為命令的原始輸出作為Buffer
返回,在開頭和結尾帶有換行符。
var os = require('os');
console.log(os.type());
有關更多參考,請參閱此鏈接: https : //millermedeiros.github.io/mdoc/examples/node_api/doc/os.html
另一種選擇可以是 npm 庫:“平台”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.