Vbscript &引用;少于;未评估的报表

Vbscript &引用;少于;未评估的报表,vbscript,Vbscript,遇到这个问题。尝试使用小于语句卸载程序的所有早期版本并安装新版本。它不会识别小于的版本,每次都会卸载并重新安装最新版本 Option Explicit Const HKEY_LOCAL_MACHINE = &H80000002 Dim Msg, MsgBoxStyle, RegKey, NAMProductKey, NAMProductName, NAMVersion '=== START Check for Cisco AnyConnect Network Access Manag

遇到这个问题。尝试使用小于语句卸载程序的所有早期版本并安装新版本。它不会识别小于的版本,每次都会卸载并重新安装最新版本

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
选项显式
Const HKEY_本地_机器=&H8000002
Dim Msg、MsgBoxStyle、RegKey、NAMProductKey、NAMProductName、NAMVersion
'==开始检查Cisco AnyConnect网络访问管理器<3.1.05170
子GetNAMKey()
Dim oReg、sPath、aKeys、sName、sKey、sVersion
设置oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\。\root\default:StdRegProv”)
sPath=“软件\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall”
oReg.EnumKey HKEY_本地_机器,斯帕斯,阿凯斯
为aKeys的每个sKey
oReg.GetStringValue HKEY\ U本地\计算机,sPath&“\”和sKey,“显示名称”,sName,“显示版本”,sVersion
如果不是IsNull(sName),则
如果(sName=“Cisco AnyConnect网络访问管理器”),则
NAMProductKey=sKey
NAMProductName=sName
NAMVersion=sVersion
如果结束
如果结束
下一个
端接头
'=开始卸载引用==
子Uni(键、名称)
Dim cmd、objShell、iReturn、oshell
cmd=“%SystemRoot%\System32\msiexec.exe/q/x”&key
设置objShell=wscript.createObject(“wscript.shell”)
objShell.LogEvent 0,“删除产品密钥[”&Key&“]”下的程序[”&name&“],&vbCrLf&“执行命令:”&vbCrLf&cmd
iReturn=objShell.Run(cmd,1,TRUE)
如果(iReturn=0),则
objShell.LogEvent 0,“程序[”&name&“]已成功删除”
其他的
objShell.LogEvent 0,“未能删除程序[&name&]”
如果结束
Set objShell=Nothing
端接头
'==开始调用(这是脚本的逻辑。)
暗淡的物体
设置objWSH=CreateObject(“WScript.Shell”)
NAMProductKey=“”
NAMProductName=“”
NAMVersion=“”
调用GetNAMKey()
如果不是(NAMProductKey=“”),则
如果(NAMVersion<“3.1.05170”),则
调用uni
NAMProductKey=“”
NAMProductName=“”
NAMVersion=“”
调用GetNAMKey()
如果(NAMProductKey=“”),则
'现在我们需要为静默Msi安装生成“msiexec.exe/a”Msi file.Msi“/quiet/norestart”
objWSH.运行“msiexec.exe/i”+Chr(34)+“C:\Users\sek\Music\Cisco ISE\AnyConnect网络访问管理器\AnyConnect-nam-win-3.1.05170-k9.msi”+Chr(34)+“/quiet/norestart”
如果结束
如果结束
其他的
'现在我们需要为静默Msi安装生成“msiexec.exe/a”Msi file.Msi“/quiet/norestart”
objWSH.运行“msiexec.exe/i”+Chr(34)+“C:\Users\sek\Music\Cisco ISE\AnyConnect网络访问管理器\AnyConnect-nam-win-3.1.05170-k9.msi”+Chr(34)+“/quiet/norestart”
如果结束

除非您对Cisco如何命名其版本有非常具体的了解,否则您不能像这样比较它们

您使用的方法是字符串比较,它遵循一些词典标准规则。 因此,类似3.2的版本编号将被视为大于3.10

为了解决这个问题,您必须以“.”作为分隔符拆分字符串,并单独比较subversion编号

然而,这只是一个普遍的观察,而不是错误评估的直接原因。 我认为原因在于您的GetStringValue调用。
这个方法不能一次返回2个值,所以我有点困惑,这是如何在没有错误的情况下执行的。但是,它解释了版本号未正确返回的原因。您需要第二个GetStringValue调用。

在比较之前,
NAMVersion
的值是多少?