locked
vbscript comparing registry key software versions - problem RRS feed

  • Question

  • Function GetNACKey()
    
      Dim oReg, sPath, aKeys, sName, sKey, sVersion
      Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
      sPath = "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
      oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aKeys
    
      For Each sKey in aKeys
        oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayName", sName
        oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayVersion", sVersion
    
        If Not IsNull(sName) Then
          If (sName = "Cisco NAC Agent") Then
            NACProductKey = sKey
            NACProductName = sName
            NACVersion = sVersion
          End If
        End If
      Next
    
    End Function
    
    
    Dim objWSH
    Set objWSH = CreateObject("WScript.Shell")
    
    'NAC
    
    NACProductKey = ""
    NACProductName = ""
    NACVersion = ""
    
    Call GetNACKey()
    
    If (NACProductKey <> "")  Then
    WScript.StdOut.Write("NAC: Found NAC...")
      If (NACVersion <> "4.9.2.8") Then
        WScript.StdOut.Write("Version not equal to 4.9.2.8...")
        Call UninstallUNI(NACProductKey, NACProductName)
    
        NACProductKey = ""
        NACProductName = ""
        NACVersion = ""
    
        Call GetNACKey()
    
        If (NACProductKey = "") Then
          WScript.StdOut.Write("NAC: Inside IF installing...")
          objWSH.Run "msiexec.exe /i " + Chr(34) + "\\mydomain\softdist\Software\CiscoISE\CiscoNAC\nacagentsetup-win-4.9.2.8.msi" + Chr(34) + " /quiet /norestart",1, True
        End If
      End If
    Else
      WScript.StdOut.Write("NAC: No NAC Found...Installing...")
      objWSH.Run "msiexec.exe /i " + Chr(34) + "\\mydomain\softdist\Software\CiscoISE\CiscoNAC\nacagentsetup-win-4.9.2.8.msi" + Chr(34) + " /quiet /norestart",1, True
    End If

    Can anyone explain to me why this doesn't work in the IF NAC version <> version.  We used the exact same code with a different application and it works fine.  The only difference is the other application has two decimal spaces other than three as in this one. Does vbscript not like to read three decimal places?
    Wednesday, December 31, 2014 5:04 PM

Answers

  • Thanks tried it but it didn't work.  I figured out the problem though.  The DisplayName key from the registry had a space at the end of it.  So instead of "Cisco NAC Agent" as the proper display name, it was "Cisco NAC Agent ".  Go figure.  Thanks for your help everyone!  Happy New Year!
    • Marked as answer by sek1212 Wednesday, December 31, 2014 8:42 PM
    Wednesday, December 31, 2014 8:42 PM

All replies

  • So I don't have to read it: What is the script supposed to do?

    Also, tell what you want to accomplish, now how you think you need to do it.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 31, 2014 5:06 PM
  • It just looks for a version of a software through the registry key.  If it is less than a certain version it will call an uninstall function and then check the key version again.  Then it will install the new version.  But it keeps uninstalling no matter the version
    Wednesday, December 31, 2014 5:15 PM
  • Why do you need to uninstall first? Doesn't the newer version automatically uninstall the older version before installing? (Correctly designed packages are supposed to work this way.)

    -- Bill Stewart [Bill_Stewart]

    Wednesday, December 31, 2014 5:19 PM
  • Try it this way:

    '
    If Trim(NACVersion) = "4.9.2.8" Then
        MsgBox "Versions Match"
    Else
        MsgBox "Version installed " & NACVersion
    End If


    ¯\_(ツ)_/¯

    Wednesday, December 31, 2014 5:58 PM
  • Thanks tried it but it didn't work.  I figured out the problem though.  The DisplayName key from the registry had a space at the end of it.  So instead of "Cisco NAC Agent" as the proper display name, it was "Cisco NAC Agent ".  Go figure.  Thanks for your help everyone!  Happy New Year!
    • Marked as answer by sek1212 Wednesday, December 31, 2014 8:42 PM
    Wednesday, December 31, 2014 8:42 PM
  • Thanks tried it but it didn't work.  I figured out the problem though.  The DisplayName key from the registry had a space at the end of it.  So instead of "Cisco NAC Agent" as the proper display name, it was "Cisco NAC Agent ".  Go figure.  Thanks for your help everyone!  Happy New Year!

    Thanks for the explanation however immpossible it is.  The script would have had a completely different output if that were the case.

    Here is the line that you would have seen: "WScript.StdOut.Write("NAC: No NAC Found...Installing...")"

    I suspect we will never know what the issue was.


    ¯\_(ツ)_/¯

    Wednesday, December 31, 2014 11:23 PM