2

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

我有脚本的零碎部分,但我似乎无法弄清楚如何在脚本中合并 OS 和 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 脚本

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
4

2 回答 2

3

尽管 Office 部分有点慢,但它确实有效。

只需将其包含在名称为getversions.vbs的文件中即可

在我的电脑上,它打印:

微软视窗 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
于 2012-12-04T18:24:39.690 回答
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
于 2013-10-19T14:36:14.247 回答