I've got a few GUI applications I've developed and I made them "check in" to see if they're running the latest version and if not, ask the user to update it.
So far I've gotten away with the script below. It basically reads the ProductVersion of the app, gets rid of the periods and converts it to an int. Then it reads an ini file I have on our server, finds the correct app, and converts that to an int. Then it simply compares the two and if the "online version" is a bigger number, tell the user to update:
The ini file looks like this:I was using 4 digits (1.2.3.4) and recently read the Windows Installer doesn't read the 4th digit and decided to rework things as it was really unnecessary anyway for my purposes and don't want to run into issues down the road if I change things. But I can't seem to get the compare to work if I try and read the value in the ini file without removing the periods. I was hoping to use the code below but it doesn't seem to read the information properly for the online version, and I am probably misusing the System.Version part:
How do I convert the data from the ini file to the same format as the ProductVersion, and assuming I do that right will the "$CurrentVersion -lt $OnlineVersion" math actually work if, for example, current version is 1.2.31 and online is 1.2.4?
I know this is scripting help but it's specific to a GUI Application so hopefully I put this in the right spot. Also I know this is probably pretty janky so if you have a better way I'm open to suggestions Thank you for your help!
So far I've gotten away with the script below. It basically reads the ProductVersion of the app, gets rid of the periods and converts it to an int. Then it reads an ini file I have on our server, finds the correct app, and converts that to an int. Then it simply compares the two and if the "online version" is a bigger number, tell the user to update:
Code:
$IniContents = Get-IniFile "\\SERVERNAME\sysvol\SERVERNAME\scripts\PowershellTools.ini"$CurrentVersion = [System.Windows.Forms.Application]::ProductVersion.Replace(".", "").Trim()$OnlineVersion = $IniContents.AccountCreationTool.version.Replace(".", "").Trim()[int]$CurrentVersionInt = [System.Convert]::ToInt32($CurrentVersion, 10)[int]$OnlineVersionInt = [System.Convert]::ToInt32($OnlineVersion, 10)if ($CurrentVersionInt -lt $OnlineVersionInt){ blah blah blah }
Code:
[AccountCreationTool]version=2.9.5.1[SupportToolkit]version=1.3.2.0[DHCPCleanupUtility]version=1.2.0.0
Code:
$CurrentVersion = [System.Windows.Forms.Application]::ProductVersion$OnlineVersion = [System.Version]::Parse($IniContents.AccountCreationTool.version)
I know this is scripting help but it's specific to a GUI Application so hopefully I put this in the right spot. Also I know this is probably pretty janky so if you have a better way I'm open to suggestions Thank you for your help!
Statistics: Posted by Greg0055 — Thu Jan 25, 2024 9:50 am