Powershell 操作系统架构与 NodeJs process.arch

Powershell operating system architecture vs NodeJs process.arch

我正在使用内部调用 process.arch 的 NodeJs 应用程序来获取系统架构,然后根据结果构建路径,例如。 - path/to/file/x64/file(应用程序是 selenium-standalone NPM 包)。

现在我需要在 PowerShell 脚本中构建相同的路径,因此我还需要获取系统架构。但是用 f.ex 来做。 (Get-WmiObject Win32_Processor).AddressWidth returns 结果没有 x - 只是 64 所以我的路径最终是 path/to/file/64/file 这是错误的。我当前的解决方法是显式添加 x:

$arch = (Get-WmiObject Win32_Processor).AddressWidth
if ($arch -eq 32) { $arch = 'x32' } 
if ($arch -eq 64) { $arch = 'x64' } 

您认为这样做安全吗?或者有没有一种方法可以从 powerShell 获得它已经分配了 x

process.arch 描述了 当前进程 - 因为完全有可能在 64 位操作系统上 运行 32 位(甚至 16 位)进程。

要确定 运行ning PowerShell 进程是 32 位还是 64 位(无论 OS 架构如何),请使用 [Environment]::Is64BitProcess:

$arch = if([Environment]::Is64BitProcess) { 'x64' } else { 'x32' }