VBS或Bat - 确定操作系统和Office版本

时间:2012-12-03 23:13:13

标签: windows batch-file vbscript ms-office

是否有人拥有可在同一脚本中确定Windows操作系统和Office版本的脚本。

我有一些脚本,但我似乎无法弄清楚如何在脚本中加入操作系统和Office版本。我现在开始蝙蝠,现在我转向VBS,因为它似乎能够提供更多细节,但如果有人可以帮助我在下面提供逻辑,我可能会继续前进。

我想知道如何设置这样的脚本。

If Windows 7 64bit & Office 2010
    do this
If Windows XP 32bit & Office 2007
    do this  
If Windows 7 & Office 2007
    do this

检测Windows版本的代码 - BAT SCRIPT

Echo Please wait.... detecting Windows OS version...
ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto done

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto done

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto done

if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

systeminfo | find "OS Name" > %TEMP%\osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7

echo %vers% | find "Windows Server 2008" > nul
if %ERRORLEVEL% == 0 goto done

echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_7

goto warnthenexit

2 个答案:

答案 0 :(得分:2)

虽然Office部分有点慢,但确实有效。

只需将其包含在名称为 getversions.vbs

的文件中

在我的电脑上打印出来:

Microsoft Windows 8企业版

Microsoft Office 32位组件2013,版本15

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")

    For Each objOperatingSystem in colOperatingSystems
        Wscript.Echo objOperatingSystem.Caption
    Next

    Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office%'")

    If colSoft.Count = 0 Then
      wscript.echo "NO OFFFICE INSTALLED" 
    else
       For Each objItem In colSoft
          Wscript.echo objitem.caption & ", Version" & Left(objItem.Version, InStr(1,objItem.Version,".")-1)
          exit for
       Next
    End If

答案 1 :(得分:1)

将此(VB脚本)文件另存为GetVersions.vbs。 有用 问候, 肖恩

Option Explicit ' Enforce variable declaration
    ' Declare objects
Dim oShell
Dim sOSVersion
Dim lOfficeVersion

Set oShell = CreateObject("WScript.Shell")

On Error Resume Next
sOSVersion = oShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")' Read the registry for the operating system version

lOfficeVersion = GetOfficeVersionNumber() ' Read the office version from the function

MsgBox "sOSVersion = " & sOSVersion & vbCrLf & "lOfficeVersion = " & lOfficeVersion

    Function GetOfficeVersionNumber()
        GetOfficeVersionNumber = ""  ' or you could use "Office not installed"
        Dim sTempValue
                    ' Read the Classes Root registry hive (it is a memory-only instance amalgamation of HKCU\Software\Classes and HKLM\Software\Classes registry keys) as it contains a source of information for the currently active Microsoft Office Excel application major version - it's quicker and easier to read the registry than the file version information after a location lookup). The trailing backslash on the line denotes that the @ or default registry key value is being queried.
        sTempValue = oShell.RegRead("HKCR\Excel.Application\CurVer\")
        If Len(sTempValue) > 2 Then GetOfficeVersionNumber = Replace(Right(sTempValue, 2), ".", "") ' Check the length of the value found and if greater than 2 digits then read the last two digits for the major Office version value
    End Function    ' GetOfficeVersionNumber
相关问题