To help you better we need some information from you.
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: PowerShell Studio 2021 5.8.188
Operating system: Windows 10 20H2
PowerShell version(s): Windows PowerShell 5.1.19041.1151
32-bit version of software? No
*** Please add details and screenshots as needed below. ***
I have a script that I compiled to an EXE. When attempting to run the EXE, certain parameters do not work, even though they do as .PS1. The parameters that do not work are of type [string]. Yes, I have [switch] parameters, and I understand those are not fully supported, but the switches run fine, and all other [string] parameters are recognized. It is just specific parameters and there is no indication as to why this is occurring.
DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
Certain parameters do not run when compiled as an EXE even though they do as a .ps1
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
- jasonrutherford
- Posts: 5
- Last visit: Tue Feb 14, 2023 7:50 pm
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
You may find the following articles helpful:
https://www.sapien.com/blog/2015/11/30/ ... able-file/
https://www.sapien.com/blog/2015/12/07/ ... able-file/
https://www.sapien.com/blog/2015/11/30/ ... able-file/
https://www.sapien.com/blog/2015/12/07/ ... able-file/
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
It would help if you provide the exact parameters used, a sample value set you use and what exactly "not working" means.
That includes how you use the parameters in your code. Please understand that we cannot see your screen or your code.
That includes how you use the parameters in your code. Please understand that we cannot see your screen or your code.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- jasonrutherford
- Posts: 5
- Last visit: Tue Feb 14, 2023 7:50 pm
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
The "exact" parameters are relatively inconsequential, right? They are custom, so it wouldn't be relevant, unless I'm missing something. But, for your edification, here's an example:
param(
[string]$SuperLongFilePathName,
[string]$Hours,
[switch]$EnablePath,
[switch]$OpenFile
)
By "not working", the EXE just fails to run when using "-Hours 12" or the likes. The event viewer shows an exception code for the application of "Exception code: 0xc0000409".
param(
[string]$SuperLongFilePathName,
[string]$Hours,
[switch]$EnablePath,
[switch]$OpenFile
)
By "not working", the EXE just fails to run when using "-Hours 12" or the likes. The event viewer shows an exception code for the application of "Exception code: 0xc0000409".
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
No, they are not inconsequential. Just from your parameters I see $SuperLongFilePathName
It is quite important what you specify there and how long that is. Windows has a limit on how long a complete command line can be.
A 0xc0000409 is a stack overflow exception. Without context, that means nothing, as we cannot tell if it is the exe engine parsing your parameters or your code doing something recursive.
So all information is of consequence. So an exact value set that you use to produce this is essential.
It is quite important what you specify there and how long that is. Windows has a limit on how long a complete command line can be.
A 0xc0000409 is a stack overflow exception. Without context, that means nothing, as we cannot tell if it is the exe engine parsing your parameters or your code doing something recursive.
So all information is of consequence. So an exact value set that you use to produce this is essential.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- jasonrutherford
- Posts: 5
- Last visit: Tue Feb 14, 2023 7:50 pm
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
Fair enough. Here are a list of params, and I'll follow with the command line used to produce the error:
param(
[string]$BackgroundColor = "8dc63f",
[string]$UpdateAuthority = "WUfB",
[string]$LogSizeKB = "500",
[string]$RebootCountdownHours = "8",
[string]$RebootCountdownMinutes = "0",
[string]$RebootCountdownSeconds = "0",
[string]$MaxDeferrals = "3",
[string]$DeferOption0 = "1",
[string]$DeferOption1 = "4",
[string]$DeferOption2 = "8",
[string]$PendingActionsCheckIntervalMinutes = "15",
[string]$WindowsUpdateRemediationLevel = 0,
[switch]$DisableBalloonNotifications,
[switch]$EnableCloseButton,
[switch]$ShowInTaskbar,
[switch]$EnableDemo,
[switch]$DisableUpdateScan,
[switch]$DisableRebootScan,
[switch]$DisableUpgradeScan,
[switch]$OverrideWUNotifications,
[switch]$OverrideCMUpdateNotifications,
[switch]$EnableVerboseLogging,
[switch]$AlwaysTopmost,
[switch]$RetryFailedInstallation
)
Command line:
install.ps1 -AlwaysTopmost -OverrideWUNotifications -OverrideCMUpdateNotifications -DisableUpdateScan -DisableRebootScan -MaxDeferrals 2 -BackgroundColor 00294D -UpdateAuthority HYBRID -RebootCountdownHours 12
If I take off "-RebootCountdownHours 12" it works. So, I'm guessing (based on what you stated above) my command line is too long... although, that doesn't explain to me why I can run it as a .ps1. Is that limited to EXE?
param(
[string]$BackgroundColor = "8dc63f",
[string]$UpdateAuthority = "WUfB",
[string]$LogSizeKB = "500",
[string]$RebootCountdownHours = "8",
[string]$RebootCountdownMinutes = "0",
[string]$RebootCountdownSeconds = "0",
[string]$MaxDeferrals = "3",
[string]$DeferOption0 = "1",
[string]$DeferOption1 = "4",
[string]$DeferOption2 = "8",
[string]$PendingActionsCheckIntervalMinutes = "15",
[string]$WindowsUpdateRemediationLevel = 0,
[switch]$DisableBalloonNotifications,
[switch]$EnableCloseButton,
[switch]$ShowInTaskbar,
[switch]$EnableDemo,
[switch]$DisableUpdateScan,
[switch]$DisableRebootScan,
[switch]$DisableUpgradeScan,
[switch]$OverrideWUNotifications,
[switch]$OverrideCMUpdateNotifications,
[switch]$EnableVerboseLogging,
[switch]$AlwaysTopmost,
[switch]$RetryFailedInstallation
)
Command line:
install.ps1 -AlwaysTopmost -OverrideWUNotifications -OverrideCMUpdateNotifications -DisableUpdateScan -DisableRebootScan -MaxDeferrals 2 -BackgroundColor 00294D -UpdateAuthority HYBRID -RebootCountdownHours 12
If I take off "-RebootCountdownHours 12" it works. So, I'm guessing (based on what you stated above) my command line is too long... although, that doesn't explain to me why I can run it as a .ps1. Is that limited to EXE?
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
The Windows command line limit is 32767. The maximum length of a command line in cmd.exe is 8191. You did not state how you packaged this particular exe, so I cannot tell which one applies.
If you look at how command line tools for almost any OS are usually designed, you will notice that parameter names are usually just long enough to be unique but as short as possible.
That is to leave room for the actual data.
So as an example you would use
install.ps1 -t -wu -cm -dus -drs -m 2 -bc 00294D -ua HYBRID -rc 12
Parameters are typically kept lowercase to make it easier on the user. You do not have to remember the exact case, the mnemonic will do and you do not need to use shift at all times while typing.
Your tool should also follow the practice of displaying an about message listing the possible parameters with an explanation when called without parameters.
If the absence of any parameter is defined as a specific action, something like -help or -? should display information.
If you look at how command line tools for almost any OS are usually designed, you will notice that parameter names are usually just long enough to be unique but as short as possible.
That is to leave room for the actual data.
So as an example you would use
install.ps1 -t -wu -cm -dus -drs -m 2 -bc 00294D -ua HYBRID -rc 12
Parameters are typically kept lowercase to make it easier on the user. You do not have to remember the exact case, the mnemonic will do and you do not need to use shift at all times while typing.
Your tool should also follow the practice of displaying an about message listing the possible parameters with an explanation when called without parameters.
If the absence of any parameter is defined as a specific action, something like -help or -? should display information.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Certain parameters do not run when compiled as an EXE even though they do as a .ps1
Just to answer your other question why this works as a .PS in a PowerShell console. The PowerShell team decided how parameters are passed within their own environment and what limits apply and when.
These conditions however do not apply to anything outside of the purview of PowerShell. So as soon as you call Windows or console executable files, the general OS rules apply again.
These conditions however do not apply to anything outside of the purview of PowerShell. So as soon as you call Windows or console executable files, the general OS rules apply again.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.