Display exe version number in label

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 6 years and 2 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
dvandekraats
Posts: 2
Last visit: Sat Apr 29, 2023 4:12 pm

Display exe version number in label

Post by dvandekraats »

I'm probably using the wrong search terms as I'm very new to PowerShell Studio. I'm trying to display the exe version of the PowerShell project I've built into an executable on the GUI form. I'm trying to retrieve the version (the same version that can be set to auto-increment every time you build a new EXE) in a string like 1.0.1.2, but I always get a NULL and my label control is blank. My code is like this:

$labelVer.Text = (Get-Command -Name $PSCommandPath).version.major + '.' + `
(Get-Command -Name $PSCommandPath).version.minor + '.' + `
(Get-Command -Name $PSCommandPath).version.build + '.' + `
(Get-Command -Name $PSCommandPath).version.revision

This is called from the form_load function. I've experimented with few changes to confirm that the $labelVer.Text will update when I run this from the Debug and I can confirm that PSCommandPath is updated, but it seems to always NULL out when I run it from within the EXE. There's an obvious gap in my knowledge to the differences between the .PS1 and the .EXE environment.

There's likely a much more simpler way of doing this and I would certainly would like to know, but I'd also like to know if I'm even close with the method I was trying to do.

PowerShell Studio 2018 v5.5.148
EXE built for 64bit, STA mode enabled
Windows 10.0.16299
PowerShell 5.1.16299.98
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Display exe version number in label

Post by jvierra »

This should get you started;

(get-process -Id $pid -FileVersionInfo).FileVersion
User avatar
dvandekraats
Posts: 2
Last visit: Sat Apr 29, 2023 4:12 pm

Re: Display exe version number in label

Post by dvandekraats »

Works perfectly. Thank you. :D
This topic is 6 years and 2 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