2012-12-03 142 views
1

是否有人有腳本可以在同一腳本中確定Windows操作系統和Office版本。VBS或Bat - 確定操作系統和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 

CODE用於檢測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 
+0

對於OS:http://stackoverflow.com/questions/4317794/a-vbscript-to-find-windows-version-name-and-the-service-包 –

回答

2

雖然辦公室的一部分是一種緩慢的,它的工作。

就包括這一個名稱的文件中像getversions.vbs

在我的電腦裏,它印:

微軟Windows 8企業

的Microsoft Office 32位組件2013,Version15

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 
+0

謝謝,我會看看。我不介意它會減慢速度,因爲它會在晚上用戶不會登錄時運行。 – brink668

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 
+0

您可能需要添加一行或兩行關於如何/爲什麼會起作用。 – dcaswell

相關問題