Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

AD - What version of Office - Script Request

Hello Script gurus!

We are ready to rollout Office 2003 at our company.  To give you an idea, we currently have a mixed bag from Office 2000, Office 2002, to Office 2003 on our computers.  I currently have a Group Policy package for the Office 2003 install with MSI configuration tested and ready to roll.  The GPO works well.  However, I would like to find a way to see what versions of Microsoft Office are on each computer under a particular OU in the domain.  

I want to make sure that the Group Policy I have in place does not get pushed to existing computers that already have Office 2003 installed.  In testing we have found a few computers where Office 2003 was already installed; when the GPO ran on these computers it totally uninstalled and removed Office 2003 altogether.  In addition, there are a small number of computers on the network that DO NOT have Microsoft Office installed.  I want to make sure that the Group Policy does not apply to those computers, and they remain unchanged.

Thanks in advance!
0
mb2010
Asked:
mb2010
  • 7
  • 5
1 Solution
 
Chris DentPowerShell DeveloperCommented:

Hi,

When office installs it creates some registry keys. These could be used as a basis for version testing.

Before going any further, when office is uninstalled I don't believe it removes these keys, so this kind of check may return false positives in some cases.

The Key we're interested in is:

HKEY_CURRENT_USER\Software\Microsoft\Office\<Version>

I've never seen they key for Office 97, it could be assumed to be 8.0 though, the rest are as follows:

9.0 is Office 2000
10.0 is Office XP
11.0 is Office 2003

This script uses Windows Management Instrumentation to access the registry, I don't know if it will run as a normal user, so let me know if not:


Option Explicit

' Registry Values

Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001

' Variable Declaration
                                                                        
Dim strComputer, strKeyPath, strSubKey
Dim objRegistry
Dim booOffice2k3
Dim arrSubKeys
                                                                        
' Connect to the registry on the local computer

strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Office"
objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys

booOffice2k3 = "FALSE"

For Each strSubKey In arrSubKeys

      If (InStr(strSubKey, "11.0") <> 0) Then
            booOffice2k3 = "TRUE"
      End If
Next

Set objRegistry = Nothing

wscript.echo booOffice2k3


The script just echos whether or not if found office at the moment, it is intended as a demonstration of how you might find out rather than a complete solution.

Let me know if it doesn't work, there's always a way :)

Chris
0
 
mb2010Author Commented:
Thanks Chris.

Your script works on my local machine.  However, I would like to apply a scrip to an entire OU in Active Directory to get computer names off all computers that do not have Office installed.  In addition, I would like computer names of all computers that have anything less than Office 2003 installed.
0
 
Chris DentPowerShell DeveloperCommented:

In theory because it uses WMI to attach to the Registry it should be able to do that without problem.

Give me a little time to write in the needed functionality and make sure it works and I'll post a new one.

Chris
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mb2010Author Commented:
Okay.  Thanks much.
0
 
Chris DentPowerShell DeveloperCommented:

Okay... a few notes first.

WMI Scripting is always a tricky subject, there are a lot of pretty easy ways to break it. So I've made the following assumptions:

1. DCOM is enabled on all Machines (HKEY_LOCAL_MACHINE\Software\Microsoft\OLE, EnableDCOM, REG_SZ, Y
2. You're running the script as a user with administrative rights over those machines

And just to make life complicated there's no guarantee it'll work on the first attempt.

But lets see how it does...

Option Explicit

' Constants

Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001

Const OFFICE_2003 = "11.0"
Const OFFICE_XP = "10.0"
Const OFFICE_2000 = "9.0"

' Part One
'
' Connect to an OU in AD and retrieve a list of Computers

Dim objRootDSE, objOrgUnit, objComputer
Dim strOrgUnit
Dim arrComputers()
Dim intComputerNumber

Set objRootDSE = GetObject("LDAP://rootDSE")
intComputerNumber = -1

' strOrgUnit is the full AD path to the OU - The domain name is added on connection as the defaultNamingContext

strOrgUnit = "ou=TargetOU,ou=ParentOU"

' Form the connection to the Organisational Unit

Set objOrgUnit = GetObject("LDAP://" & strOrgUnit  & ","  & objRootDSE.Get("defaultNamingContext"))

' Add the Computers to a new array

objOrgUnit.Filter = Array("computer")
For Each objComputer in objOrgUnit
      intComputerNumber = intComputerNumber + 1
      ReDim Preserve arrComputers(intComputerNumber)
      arrComputers(intComputerNumber) = objComputer.Name
Next

Set objComputer = Nothing
Set objOrgUnit = Nothing
Set objRootDSE = Nothing

' Part 2
'
' Attempt to Connect to the Registry for each computer in the list

Dim objRegistry
Dim strComputer, strKeyPath, strSubKey
Dim arrSubKeys
Dim booOfficeInstalled

For Each strComputer in arrComputers
      Err.Clear
      On Error Resume Next
      Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
            strComputer & "\root\default:StdRegProv")
      If Err.Number <> 0 Then
            wscript.echo "Unable to attach to Registry for " & strComputer
      Else
            ' Attach to the Software\Microsoft Key and see if Office exists
            strKeyPath = "Software\Microsoft"
            objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys

            booOfficeInstalled = "FALSE"
            For Each strSubKey in arrSubKeys
                  If (InStr(strSubKey, "Office") <> 0) Then
                        booOfficeInstalled = "TRUE"
                        wscript.echo "Office Installation found on " & strComputer
                  End If
            Next

            If booOfficeInstalled = "TRUE" Then
                  ' Attach to the Office Key to get the version
                  strKeyPath = "Software\Microsoft\Office"
                  objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
                  For Each strSubKey in arrSubKeys
                        If (InStr(strSubKey, OFFICE_2003) <> 0) Then
                              wscript.echo "Office 2003 found on " & strComputer
                        ElseIf (InStr(strSubKey, OFFICE_XP) <> 0) Then
                              wscript.echo "Office XP found on " & strComputer
                        ElseIf (InStr(strSubKey, OFFICE_2000) <> 0) Then
                              wscript.echo "Office 2000 found on " & strComputer
                        End If
                  Next
            Else
                  wscript.echo "No installation found on " & strComputer
            End If
      End If
Next
0
 
mb2010Author Commented:
Thanks.  My WMI skills are even more limited than VBS and BAT.  With VBS and BAT you just rename a notepad file from .TXT to .VBS or .BAT, the run the file.  How do you set up a WMI script to run?
0
 
Chris DentPowerShell DeveloperCommented:

It's all VBScript (.vbs), it just uses WMI as an interface in an attempt to grab information. How successful it'll be remains to be seen ;)

If the Organisational Unit selection above is a bit too clunky I can make it search for a specified OU - but really it's much more dependant on whether the registry calls work.

Chris
0
 
mb2010Author Commented:
Where would I see the output if I created a Group Policy Object and ran the script from there?  Is is possible to place the output into a TXT or CSV (whatever one has the cleaner looking output)?

BTW... I ran the most recent script on my local desktop computer and got the following results:

Windows Script Host
Script: C:\OfficeVer.vbs
Line: 30
Char: 1
Error: There is no such object on the server
Code: 80072030
Source: (null)

Also,  DCOM is enabled on all machines AND I am a domain administrator, with administrator rights to all machines on the network.
0
 
Chris DentPowerShell DeveloperCommented:

The script can't be run from Group Policy since that would run the script as a user rather than as an administrator. Although the process of reading the details from the registry is a lot easier than attempting to run it centrally.

At present it just dumps the output to the screen, where would you prefer it to go?

Line 30 will break if you haven't updated the strOrgUnit field on line 26 - it needs that to grab the list of computers. I can change it ask you for an OU and go from there though.
0
 
mb2010Author Commented:
Okay... Then I assume I have to run it from a domain controller, not a workstation.  Can you have it dump to "C:\OfficeVer" in a txt or csv file (whatever looks better)?  Yes, please have it prompt me for what OU I want to run it on.
0
 
mb2010Author Commented:
Sorry.  My father is undergoing heart surgery and I have limited Internet access.  When I return.  I plan to respond to this.  Thank you.
0
 
mb2010Author Commented:
I found this software that will meet my needs perfectly:

http://www.digitallabs.net/rsi/

Chris-Dent,

Points will still go to you for keeping things on the right track and taking time to write those scripts.  Thank you!
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now