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.
Locked
User avatar
dvandekraats
Posts: 2
Joined: Sun Feb 11, 2018 11:53 am

Display exe version number in label

Post by dvandekraats » Tue Feb 13, 2018 4:46 pm

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

User avatar
jvierra
Posts: 12552
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Display exe version number in label

Post by jvierra » Tue Feb 13, 2018 6:17 pm

This should get you started;

(get-process -Id $pid -FileVersionInfo).FileVersion

User avatar
dvandekraats
Posts: 2
Joined: Sun Feb 11, 2018 11:53 am

Re: Display exe version number in label

Post by dvandekraats » Wed Feb 14, 2018 9:35 am

Works perfectly. Thank you. :D

Locked