操作系统架构检测脚本 [英] OS architecture detection script

查看:77
本文介绍了操作系统架构检测脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为 7zip(x86 和 x64)下载了两个 .msi 安装程序.有没有人有一个简单的脚本可以用来检测操作系统架构并启动适当的 .msi 文件?

I have just downloaded the two .msi installers for 7zip (x86 and x64). Does anyone have a simple script I can use to detect the OS architecture and launch the appropriate .msi file?

推荐答案

你说的简单,但没有指定语言...

You said simple, but didn't specify a language ...

批处理(.cmd):

IF /I %PROCESSOR_ARCHITECTURE% EQU x86 (
    msiexec /qn /i 7zip_x86.msi
) ELSE (
    msiexec /qn /i 7zip_x64.msi
)

VBScript (.vbs):

VBScript (.vbs):

Set oShell = WScript.CreateObject("WScript.Shell")
proc_arch = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")

If proc_arch = 'x86' Then
    oShell.Run("msiexec /qn /i 7zip_x86.msi"), 0, true 
Else
    oShell.Run("msiexec /qn /i 7zip_x64.msi"), 0, true
End If

PowerShell (.ps1):

PowerShell (.ps1):

if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
    & msiexec /qn /i 7zip_x86.msi
} else {
    & msiexec /qn /i 7zip_x64.msi
}
# or ...
if ([Environment]::Is64BitOperatingSystem) {
    & msiexec /qn /i 7zip_x86.msi
} else {
    & msiexec /qn /i 7zip_x64.msi
}

这篇关于操作系统架构检测脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆