“不到”的陈述没有评估

时间:2014-12-16 12:46:22

标签: vbscript

遇到这个问题。尝试使用less than语句卸载所有以前版本的程序并安装新版本。它不会识别少于,并且每次都会继续卸载并重新安装最新版本。

Option Explicit

Const HKEY_LOCAL_MACHINE = &H80000002
Dim Msg, MsgBoxStyle, RegKey, NAMProductKey, NAMProductName, NAMVersion

'=== START Check for Cisco AnyConnect Network Access Manager < 3.1.05170
Sub GetNAMKey()
    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, "DisplayVersion", sVersion
        If Not IsNull(sName) Then 
            If (sName = "Cisco AnyConnect Network Access Manager") Then
                NAMProductKey = sKey
                NAMProductName = sName
                NAMVersion = sVersion
            End If
        End If
    Next
End Sub

'=Start Uninstall Reference== 
Sub UninstallUNI(key, name)
    Dim cmd, objShell, iReturn, oshell

    cmd = "%SystemRoot%\System32\msiexec.exe /q/x " & key
    Set objShell = wscript.createObject("wscript.shell")

    objShell.LogEvent 0, "Removing the program [" & name & "] under Product Key [" & key & "]" & vbCrLf & "Executing command: " & vbCrLf & cmd

    iReturn=objShell.Run(cmd,1,TRUE)

    If (iReturn = 0) Then
        objShell.LogEvent 0, "Program [" & name & "] was successfully removed"
    Else
        objShell.LogEvent 0, "Failed to remove the program [" & name & "]."
    End If

    Set objShell = Nothing  
End Sub

'=== START CALLs (This is the script's logic.)
Dim objWSH
Set objWSH = CreateObject("WScript.Shell")

NAMProductKey = ""
NAMProductName = ""
NAMVersion = "" 

Call GetNAMKey()

If Not (NAMProductKey = "") Then
    If (NAMVersion < "3.1.05170") Then
        Call UninstallUNI

        NAMProductKey = ""
        NAMProductName = ""
        NAMVersion = "" 

        Call GetNAMKey()

        If (NAMProductKey = "") Then
            'Now we need to produce "msiexec.exe /a "Msi file.msi" /quiet /norestart" for a silent MSI install
            objWSH.Run "msiexec.exe /i " + Chr(34) + "C:\Users\sek\Music\Cisco ISE\AnyConnect Network Access Manager\anyconnect-nam-win-3.1.05170-k9.msi" + Chr(34) + " /quiet /norestart"
        End If
    End If
Else
    'Now we need to produce "msiexec.exe /a "Msi file.msi" /quiet /norestart" for a silent MSI install
    objWSH.Run "msiexec.exe /i " + Chr(34) + "C:\Users\sek\Music\Cisco ISE\AnyConnect Network Access Manager\anyconnect-nam-win-3.1.05170-k9.msi" + Chr(34) + " /quiet /norestart"
End If

1 个答案:

答案 0 :(得分:2)

除非您对思科如何命名它的版本有非常具体的了解,否则您无法将它们比作这样。

您使用的方法是字符串比较,它遵循一些字典标准规则。 因此,像3.2这样的版本将被认为大于3.10。

为了解决此问题,您必须将字符串拆分为&#39;。&#39;作为分隔符并独立比较颠覆数。

然而,这更多是一般观察,而不是错误评估的直接原因。 我认为原因在于你的GetStringValue调用。 According to the API这个方法不能一次返回2个值,所以我有点疑惑这个甚至是如何执行而没有错误。它解释了为什么版本号未正确返回。你需要第二次GetStringValue调用。