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.
Locked
User avatar
stevens
Posts: 434
Joined: Wed Jun 15, 2016 2:26 am

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: 14611
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 33
Joined: Thu Aug 01, 2013 6:14 pm
Location: Melbourne, Australia
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: 434
Joined: Wed Jun 15, 2016 2:26 am

Re: Buildversion, use exeversion to show in GUI?

Post by stevens »

Thanks Nillth, works like a charm!!!

User avatar
stevens
Posts: 434
Joined: Wed Jun 15, 2016 2:26 am

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: 14611
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 434
Joined: Wed Jun 15, 2016 2:26 am

Re: Buildversion, use exeversion to show in GUI?

Post by stevens »

Ok, thanks.

jvierra
Posts: 14611
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 14611
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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

Locked