Return Windows and Office versions

Return Windows and Office versions

Post by WFA » Sat, 28 Apr 2007 07:22:02


Using Windows XP;

Could someone please post example VB Script that would return:

1) The current version of MS-Windows

2) The current version of Office

Thanks much in advance.
 
 
 

Return Windows and Office versions

Post by Marcus Sch » Sat, 28 Apr 2007 13:07:08

XP schrieb:


Windows:
http://www.yqcomputer.com/

Office:
Function GetOfficeVersion(strComputer)
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMI.ExecQuery("SELECT Version FROM Win32_Product " & _
"WHERE Name Like 'Microsoft Office %'")

If colItems.Count = 0 Then
GetOfficeVersion = "0"
Exit Function
End If

For Each objItem In colItems
GetOfficeVersion = objItem.Name & " - Version: " & _
Left(objItem.Version,InStr(1,objItem.Version,".")-1)
Exit Function
Next

Set objWMI = Nothing
Set colItems = Nothing
Set objWMI = Nothing
End Function

WScript.Echo GetOfficeVersion(".")

 
 
 

Return Windows and Office versions

Post by D.R. » Fri, 04 May 2007 15:30:02

Hi XP,

Here's a function to return Windows O/S version:


Function fs_get_os_version()
Const cs_fac = "%fs_get_os_version, "
Dim lo_net, ls_computer, lo_wmi, lo_systems, lo_os, ls_os, ll_cnt
fs_get_os_version = "(unknown)"
Set lo_net = CreateObject( "WScript.Network" )
ls_computer = lo_net.ComputerName
Set lo_wmi = GetObject( "WinMgmts:\\" & ls_computer & "\root\cimv2" )
Set lo_systems = lo_wmi.InstancesOf( "Win32_OperatingSystem" )
On Error Resume Next
ll_cnt = lo_systems.Count
If Err.Number <> 0 Then
Call s_error( cs_fac & "Unable to connect to WMI object to retrieve OS
version." )
End If
On Error Goto 0
For Each lo_os In lo_systems 'Only one instance is ever returned (the
currently active OS).
Select Case lo_os.OSType
Case 16
ls_os = "Win95"
Case 17
ls_os = "Win98"
Case 18
Select Case Left( lo_os.Version, 3 )
Case "4.0"
ls_os = "WinNT4"
Case "5.0"
ls_os = "Win2000"
Case "5.1"
ls_os = "WinXP"
Case "5.2"
ls_os = "Win2003"
Case Else
ls_os = "WinNT v" & lo_os.Version
End Select
If lo_os.ServicePackMajorVersion > 0 Then
ls_os = ls_os & " SP" & lo_os.ServicePackMajorVersion
End If
Case Else
ls_os = "(unknown)"
End Select
Next
fs_get_os_version = ls_os
End Function


N.B. You'll have to change the error raiser (Call s_error()) into something
that you use.

Regards,
Dave.
 
 
 

Return Windows and Office versions

Post by mayayan » Fri, 04 May 2007 22:47:43


That looks like it would work fine for XP on XP,
but it's an oddly-written function where Win9x is
concerned. The only version of Win9x with WMI
is ME, so that's the only version of Win9x where
this method will work. It's also the only version that's
not included in the Select Case. :)


something
 
 
 

Return Windows and Office versions

Post by D.R. » Sat, 05 May 2007 04:58:27

Hi Mayayana,

Oddly enough, those values are present in MS documentation:
http://www.yqcomputer.com/
http://www.yqcomputer.com/

ME isn't included in my own function because I never used it.

Thanks again,
Dave.