Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to check Version using possibly 'Split' for several decimals

Status
Not open for further replies.

gminoc01

IS-IT--Management
Jan 13, 2012
5
US
I downloaded script via:
I need to modify the script to reflect versions < 12.1.44.1 from lines below. I receive an error because code can't find the string utilizing multiple decimals. I think the coincidence relates to line VersionArray = Split(strVersion, ".")
I've tried changing to Split(strVersion, "\.") yet didn't work. Could someone please assist?


If Left(strName, 21) = "CITRIX ONLINE PLUG-IN" Then
'Comment the IF & End If lines out if you want to remove all "Citrix Online Plug-in" 's.
'This If statement will leave version 12.0 and higher installed.
If Version < 12.0 Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If
End If
Next
 
What error is returned?
Try echoing the value of strVersion before you call the split function to see if the value is something reasonable.

If the value returned is reasonable, do you need to use split at all? Try out the code below with different values for strVersion and see if it meets your requirements.
Code:
strVersion = "12.1.44.2"
strVersionKeep = "12.1.44.1"
if strVersion < strVersionKeep then
	wscript.echo("uninstall this version: " & strVersion & " < " & strVersionKeep)
else
	wscript.echo("keep this version: " & strVersion & " >= " & strVersionKeep)
end if
 


Of course, you would have a problem with this, would you not???
Code:
strVersion = "12.1.44.2"
strVersionKeep = "12.1.44.10"
if strVersion < strVersionKeep then
'.....
since ("12.1.44.10" < "12.1.44.2")

So you really DO need to evaluate the numeric value of the 4th string.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,
good catch.

So now we are back to:
[ol][li]What error is returned?[/li]
[li]What is the value of strVersion before the split is attempted?[/li][/ol]
 



is the Split function available?

I can remember having to write my own split function, which is really not difficult, using other available string functions.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The script works great if version < 12.0

However, if I change to < 12.1.44 I get error: Expected 'Then' Basically, the second decimal causes an error. Please refer to code below:

'Requirements: Administrative Privileges
const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Function UninstallApp(strDisplayName, strVersion, strID, strUninstall)
Dim objShell
Dim objFS
'WScript.Echo "Attempting to uninstall: " & strDisplayName & " v" & strVersion

If strID = "" Then 'We don't know the GUID of the app
'Look at the Uninstall string and determine what is the
'executable and what are the command line arguments.
Set objFS = CreateObject("Scripting.FileSystemObject")

strExecutable = ""

'Start from the beginning of the string and see if we can fine the excutable in the string
For X = 0 to Len(strUninstall)
strExecutableTest = Left(strUninstall, X)
strExecutableTest = Replace(strExecutableTest, """", "")
'Test to see if the current string is a file.
If objFS.FileExists(strExecutableTest) Then
strExecutable = Trim(strExecutableTest)
intExecLength = X
End If
Next

If strExecutable = "" Then
'WScript.Echo "Bad string or the executable does not exist: " & strUninstall
Exit Function
Else
strArguments = Right(strUninstall, Len(strUninstall) - intExecLength)
'WScript.Echo "The executable is: " & strExecutable
'WScript.Echo "The arguments are: " & strArguments
End If

Uninstall = """" & strExecutable & """ " & strArguments

If InStr(Uninstall, "ISUNINST.EXE") > 0 Then
Uninstall = Uninstall & " -a"
End If
Else 'We have the GUID
Uninstall = """MSIEXEC.EXE"" /PASSIVE /X" & strID
End If

'WScript.Echo "...Executing: " & Uninstall

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run Uninstall, 1 , 1

Set objShell = Nothing
End Function

'WScript.Echo ""
'WScript.Echo Now() & " - Searching for old Citrix Clients..."

Set ObjWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
ObjWMI.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each Product In arrSubKeys
objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "DisplayName", strDisplayName
objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "DisplayVersion", strVersion
objWMI.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & Product, "UninstallString", strUninstall

strName = UCase(strDisplayName)

'Grab the GUID of the MSI if available.
If Left(Product, 1) = "{" And Right(Product, 1) = "}" Then
strID = Product
Else
strID = ""
End If

'Determine version of the Product
If strVersion <> "" Then
VersionArray = Split(strVersion, ".")
If UBound(VersionArray) > 0 Then
'Verify that only numbers are in the version string
If IsNumeric(VersionArray(0)) And IsNumeric(VersionArray(1)) Then
Version = CDbl(VersionArray(0) & "." & VersionArray(1))
Else
Version = ""
End If
End If
Else
Version = ""
End If

'Citrix has used many different Client names throughout the years. This
'should capture most, if not all, of them.

If strName = "CITRIX ICA CLIENT" Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If

If strName = "CITRIX PROGRAM NEIGHBORHOOD" Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If

If strName = "METAFRAME PRESENTATION SERVER CLIENT" Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If

If strName = "CITRIX PRESENTATION SERVER CLIENT" Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If

'Added
If strName = "CITRIX ICA WEB CLIENT" Then
'Unfortunately, CTXSETUP.exe doesn't allow a silent uninstall.
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If

If Left(strName, 21) = "CITRIX ONLINE PLUG-IN" Then
'Comment the IF & End If lines out if you want to remove all "Citrix Online Plug-in" 's.
'This If statement will leave version 12.0 and higher installed.
If Version < 12.0 Then
UninstallApp strDisplayName, strVersion, strID, strUninstall
End If
End If
Next

'WScript.Echo Now() & " - Search Complete."
'WScript.Echo ""
pt will be useful when different versions of Citrix clients are installed in the environment


 
Here, have a function that converts a legitimate version (by legitimate, I mean one that follows the Windows SDK rules) into a long.

And longs are easily compared ...
Code:
[blue]Function StringVerToLong(strVer)
    Converter = &H1000000
    For Each element In Split(strVer, ".")
        StringVerToLong = StringVerToLong + element * Converter
        Converter = Converter / 256
    Next
End Function[/blue]

Then

If Version < 12.0 Then

becomes

If StringVerToLong(Version) < StringVerToLong("12.0") Then
 
Could I have you implement Function into the script and re-post the full script? I'm not sure where to put it?

I'm assuming If StringVerToLong(Version) < StringVerToLong("12.0") Then

would actually be

I'm assuming If StringVerToLong(Version) < StringVerToLong("12.1.44") Then

Thank You,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top