Compiled Script Terminates with "Line 1: The handle is invalid error"

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.

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 8 years and 5 days 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.
User avatar
New_Datacom
Posts: 2
Last visit: Thu Nov 17, 2022 2:48 pm

Compiled Script Terminates with "Line 1: The handle is invalid error"

Post by New_Datacom »

Product, version and build: PowerShell Studio 5.2.119.0 (Running elevated)
32 or 64 bit version of product: x64
Operating system: Windows 10
32 or 64 bit OS: x64
PowerShell Version: 5.0.10586.122

Only in a compiled script (.EXE) do I get the following after some issue connecting to a remote server or executing SQL connect where the connection fails:
  • Line 1: The handle is invalid
There is no other output and the error does not occur in the uncompiled .ps1 script.

Any ideas?

Regards
G
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Compiled Script Terminates with "Line 1: The handle is invalid error"

Post by Alexander Riedel »

You do not mention what settings you use when you create the executable, nor do we know what that line 1 contains. Usually this happens when your otherwise pre-existing conditions do not apply. E.g. You did not package to require elevation when you should have, wrong platform, wrong powershell version, need STA mode etc.
Check these and let us know what the line causing the error is.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
New_Datacom
Posts: 2
Last visit: Thu Nov 17, 2022 2:48 pm

Re: Compiled Script Terminates with "Line 1: The handle is invalid error"

Post by New_Datacom »

Here is the requested information:

Line 1 is comments:
##########################################################################

The 1st non-comment line on line 93 is:
param

I should mention that application being compiled is some 6,900+ lines of code

The compiler info is:

Engine Settings
==============
Platform: SAPIEN PowerShell V3 Host (Command line) x64
STA Mode: not selected
Manifest Creation: Embed a default manifest for elevation
Run Mode: Current user

Execution Restrictions
======================
Windows 8.1, 8 & 7 selected
No build options selected

The compiling machine is Windows 10 with PowerShell 5

The application is run from an elevated prompt and the error occurs when running in a Windows 2012 R2 environment; PowerShell ver 5.0.10586.117

For example I can get it to occur if "Send-MailMessage" has an invalid -From address parsed from an INI file set by the user. e.g. they have "no-reply" instead of "no-replay@somedomain.co.nz" or using Register-ScheduledTask

If the same application is run uncompiled, it generates the normal warning or error messages and continues running -- compiled it abends with the message mentioned.

I will try to build an EXE with just a few lines of code to see if it still crashes.

Thanks
G
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Compiled Script Terminates with "Line 1: The handle is invalid error"

Post by Alexander Riedel »

Please check if you set your $ErrrorActionpreference in your profile. If so, you need to set it to the same level in your script. Packaged scripts will not execute any powershell profile.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 8 years and 5 days 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.