Buildversion, use exeversion to show in GUI?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Buildversion, use exeversion to show in GUI?

Post by stevens »

Hi,

I convert my powershell GUI into an exe/msi and use the 'auto-increment' of exe, then use exe for version in msi.
First: if generating MSI, should I first generate exe or will the msi creation generate the exe (I think I should, but just checking)?
Second: I'd like to show the version in the form header (I put it into the globals.ps1 now $Version ='1.0.0.0', then at formload, Title = $version ...
Can I read the version somewhere from a variable instead of putting the version into the globals.ps1?

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Buildversion, use exeversion to show in GUI?

Post by jvierra »

I recommend posting issues of how to use PSS to the Customer Support forum for PSS. Sapien techs will answer your questions about the product itself. The Community Forums are for PowerShell specific questions/
User avatar
Nillth
Posts: 34
Last visit: Mon Oct 30, 2023 10:52 pm
Has voted: 2 times

Re: Buildversion, use exeversion to show in GUI?

Post by Nillth »

you can call the following from inside your script.
It will pull determine the running file and pull the version info from it.

Code: Select all

$RuntimeFileInfo = Get-Item $hostinvocation.MyCommand.path
$RuntimeVersion = $($RuntimeFileInfo.VersionInfo.ProductVersion)
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Buildversion, use exeversion to show in GUI?

Post by stevens »

Thanks Nillth, works like a charm!!!
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Buildversion, use exeversion to show in GUI?

Post by stevens »

It worked fine, but it appears my GUI throws errors on that code all the time.
When running the GUI via console, I see errors all the time which makes that my gui takes up to a minute to load :-(

l\Globals.ps1:330 char:29
+ $RuntimeFileInfo = Get-Item $hostinvocation.MyCommand.path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Item], ParameterBindingValidat
ionException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Micro
soft.PowerShell.Commands.GetItemCommand
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Buildversion, use exeversion to show in GUI?

Post by jvierra »

I repeat myself. In pojects use the following function to get teh script path.

Get-ScriptDirectory

It is the only way to get the path both as a script and as a package.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Buildversion, use exeversion to show in GUI?

Post by stevens »

Ok, thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Buildversion, use exeversion to show in GUI?

Post by jvierra »

stevens wrote: Mon Apr 27, 2020 12:08 am No idea what you are trying to say.
The code that is erring won't work outside of an EXE.

What is it that you want the version of? PowerShell? A file? Windows?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Buildversion, use exeversion to show in GUI?

Post by jvierra »

To get the current EXE version
[system.diagnostics.process]::GetCurrentProcess().ProductVersion

To get the file version:
[system.diagnostics.process]::GetCurrentProcess().MainModule.FileVersion
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked