แชร์ผ่าน


How to check Project 2007 version using VBA?

[ Updated 4/25/2011 – modified code to support Windows 7, please not that this functionality is out of the box in Project Server 2010 and no longer requires such VBA script!]

A great question we heard this morning during the Project 2007 SP2 webcast and every time we release a server and desktop software update for Project 2007 and Project Server 2007, is how do I ensure the desktop contains the proper software updates? For instance how I do ensure that ALL desktop version for Project that connect to Project Server have Service Pack 2 installed?

Thanks to Adrian Jenkins please find below two easy way to achieve this by leveraging VBA (macro) within the Enterprise Global.

A quick demo first:

I try to save a plan and I will get the following warning: and WinProj will automatically be closed! image

In this first approach change MIN_PROJ_VERSION to the latest SP2 version number: 6425 

Feel free to customize the Warning message at will!

 Declare Function RegCloseKey& Lib "advapi32.dll" (ByVal hKey&) 
Declare Function RegOpenKeyExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszSubKey$, ByVal dwOptions&, ByVal samDesired&, lpHKey&) 
Declare Function RegQueryValueExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, ByVal lpDataBuff$, nSize&) 
Declare Function RegQueryValueEx& Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, lpDataBuff&, nSize&)

Const MIN_PROJ_VERSION = 6330

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Const ERROR_SUCCESS = 0&
Const REG_SZ = 1&                          ' Unicode nul terminated string
Const REG_DWORD = 4&                       ' 32-bit number

Const KEY_QUERY_VALUE = &H1&
Const KEY_SET_VALUE = &H2&
Const KEY_CREATE_SUB_KEY = &H4&
Const KEY_ENUMERATE_SUB_KEYS = &H8&
Const KEY_NOTIFY = &H10&
Const KEY_CREATE_LINK = &H20&
Const READ_CONTROL = &H20000
Const WRITE_DAC = &H40000
Const WRITE_OWNER = &H80000
Const SYNCHRONIZE = &H100000
Const STANDARD_RIGHTS_REQUIRED = &HF0000 
Const STANDARD_RIGHTS_READ = READ_CONTROL 
Const STANDARD_RIGHTS_WRITE = READ_CONTROL 
Const STANDARD_RIGHTS_EXECUTE = READ_CONTROL 
Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY 
Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY 
Const KEY_EXECUTE = KEY_READ

Sub ProjectVer()

    Dim projVersion As String
    Dim version As String
    
    projVersion = RegGetValue$(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109B30000000000000000F01FEC\InstallProperties", "DisplayVersion")
    version = Mid(projVersion, 6, 4)
    If (CInt(version) < MIN_PROJ_VERSION) Then
        
        MsgBox "Your version of Winproj.exe is not valid and may cause problems." & Chr(13) & Chr(13) & _
        "The installation of new version of Microsoft Project is required!" & Chr(13) & Chr(13) & _
        "Required Version: " & Left(projVersion, 5) & MIN_PROJ_VERSION & ".XXXX" & (Chr(13)) & _
        "Found Version:     " & projVersion & Chr(13) & Chr(13) & _
        "Microsoft Project will now Exit." _
        , vbExclamation, "Program Version Check"
        
        Application.FileExit pjDoNotSave
        
    End If
    
End Sub

Function RegGetValue$(MainKey&, SubKey$, value$)
   ' MainKey must be one of the Publicly declared HKEY constants.
   Dim sKeyType&       'to return the key type.  This function expects REG_SZ or REG_DWORD
   Dim ret&            'returned by registry functions, should be 0&
   Dim lpHKey&         'return handle to opened key
   Dim lpcbData&       'length of data in returned string
   Dim ReturnedString$ 'returned string value
   Dim ReturnedLong&   'returned long value
   If MainKey >= &H80000000 And MainKey <= &H80000006 Then
      ' Open key
      ret = RegOpenKeyExA(MainKey, SubKey, 0&, KEY_READ, lpHKey)
      If ret <> ERROR_SUCCESS Then
         RegGetValue = ""
         Exit Function     'No key open, so leave
      End If
      
      ' Set up buffer for data to be returned in.
      ' Adjust next value for larger buffers.
      lpcbData = 255
      ReturnedString = Space$(lpcbData)

      ' Read key
      ret& = RegQueryValueExA(lpHKey, value, ByVal 0&, sKeyType, ReturnedString, lpcbData)
      If ret <> ERROR_SUCCESS Then
         RegGetValue = ""   'Value probably doesn't exist
      Else
        If sKeyType = REG_DWORD Then
            ret = RegQueryValueEx(lpHKey, value, ByVal 0&, sKeyType, ReturnedLong, 4)
            If ret = ERROR_SUCCESS Then RegGetValue = CStr(ReturnedLong)
        Else
            RegGetValue = Left$(ReturnedString, lpcbData - 1)
        End If
    End If
      ' Always close opened keys.
      ret = RegCloseKey(lpHKey)
   End If
End Function

Another way to validate the desktop version, uses the file system. The only challenge with this approach is determining the location of the Program Files directory.

 Sub projVersion()
    Dim MainFolderName As String
    Dim LastMod As String
    Dim Created As String
    Dim Size As String
    Dim projVersion As String
      
    Set objShell = CreateObject("Shell.Application")
   
    MainFolderName = "C:\Program Files\Microsoft Office\Office12"
     
    Set FSO = CreateObject("scripting.FileSystemObject")
    Set oFolder = FSO.GetFolder(MainFolderName)
     'error handling to stop the obscure error that occurs at time when retrieving DateLastAccessed
    On Error Resume Next
    For Each fil In oFolder.Files

        Set objFolder = objShell.Namespace(oFolder.Path)
        Set objFolderItem = objFolder.ParseName(fil.Name)
                
        Select Case UCase(fil.Name)
            Case Is = "WINPROJ.EXE"
                LastMod = fil.DateLastModified
                Created = fil.DateCreated
                Size = fil.Size
                MsgBox ("File: " + fil.Name + " Last Modified: " + LastMod + " Created: " + Created + " Size: " + Size)
                'do all of the normal tests here to determine which version you need and which you have. See above.
        End Select
        
    Next

End Sub

Comments

  • Anonymous
    April 29, 2009
    For those of you on the on SP2 webcast this morning, a question that we hear often around updates come

  • Anonymous
    May 04, 2009
    Can someone elaborate on where in the Global this would reside? I've tried adding this as a module and adding it to the project open event without success.

  • Anonymous
    May 05, 2009
    I have the same problem llike azjimwoodny May be needed more deteail instruction?

  • Anonymous
    May 05, 2009
    Yeah, could we get some more specific insructions?

  • Anonymous
    May 12, 2009
    Hello All, Here are few more instructions in order to complete the Enterprise Global uploading. Add the following lines to the "Thisproject.cls" class module of the Checked-out Global Enterprise project. Private Sub Project_Open(ByVal pj As Project)    Call Utilities.GetProjectVersionFromRegistry End Sub ====================== !!! VERY IMPORTANT !!! ====================== You may have to upgrade your code or do any other operation after you have uploaded the module itself. If the Project Version is no longer the same of your local machine, you understand that you may not be able to get to the Visual Basic Editor since the macro is made to close the application. If this is your case, you may be able to tweak the Global.PT locally on your machine by getting to it at the following location : C:Documents and Settings%UserName%Application DataMicrosoftMS Project121033 Back it up first (in order to restore it if things turn wrong), and then delete it in order to be able to open MS Project and revisit Visual Basic Editor. Microsoft Project will reload a new instance of it on the next openning. BTW, I have been using it and everything went fine. I had to add another GUID since some of our users are using MS Project Professional and others are using MS Project Enterprise version. Here is my addition : ' Check for "00002109B30000000000000000F01FEC" Id for Microsoft Office Professional 2007    '    projVersion = RegGetValue$(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products�0002109B30000000000000000F01FECInstallProperties", "DisplayVersion")    version = Mid(projVersion, 6, 4)    If (Len(version) > 0) Then        ' ' Check for "00002109030000000000000000F01FEC" Id for Microsoft Office Enterprise 2007        '        projVersion = RegGetValue$(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products�0002109030000000000000000F01FECInstallProperties", "DisplayVersion")        version = Mid(projVersion, 6, 4)    End If Hope this will help. Regards, Jean

  • Anonymous
    May 12, 2009
    Oups! Wrong cut n paste sorry... Replace the ">" sign by this one "=". So you may have this instead : ' Check for "00002109B30000000000000000F01FEC" Id for Microsoft Office Professional 2007 ' projVersion = RegGetValue$(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products�0002109B30000000000000000F01FECInstallProperties", "DisplayVersion") version = Mid(projVersion, 6, 4) If (Len(version) = 0) Then    ' Check for "00002109030000000000000000F01FEC" Id for Microsoft Office Enterprise 2007    '    projVersion = RegGetValue$(HKEY_LOCAL_MACHINE, "SoftwareMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products�0002109030000000000000000F01FECInstallProperties", "DisplayVersion")    version = Mid(projVersion, 6, 4) End If

  • Anonymous
    May 26, 2009
    Very useful bit of code, especially if you are trying to deploy in a slightly chaotic environment. If I am right, the key that it checks is the one that is updated on the installation of a service pack - so it will only show 12.0.4518.1016, 12.0.6215.1000 or the SP2 value.   what can you do if you want to ensure that at least the Infrastructure Update or a later CU is installed, say 6319 to 6335.  Is there a key you can use to call to? thanks David.

  • Anonymous
    February 25, 2010
    I agree with David. This is useful VBA and can be very effective in preventing users from accessing plans with unpatched versions of MSP. We would like to implement but would like to cross check against a registry key that is Aug CU or higher. The reason being the Aug CU fixed an issue where users editing the eGlobal with Sp2 installed caused a corruption (see http://projectserverblogs.com/?p=2659) Anyway, any help identifying a key to reference in the VBA code would be appreciated. Sláinte Shane

  • Anonymous
    April 08, 2011
    This vba works well with xp and server 2003 machines.. but we are not able to check the MS Project version on the Windows 7 machine and windows server 2008. Could you help how to check the version for MS Project running on windows 7 machine too? Thanks in Adavance...

  • Anonymous
    September 26, 2011
    maybe one should mention that the data need not be found under the product key 00002109B30000000000000000F01FEC but in some rare cases I yet can't explain are registered below the product key 00002119B30000000000000000F01FEC (regard the little '1' difference!).