Setting ExecutionPolicy when building a script

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 7 years and 6 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.
User avatar
wayne_Avery
Posts: 30
Last visit: Tue Feb 01, 2022 2:25 pm

Setting ExecutionPolicy when building a script

Post by wayne_Avery »

Product, version and build: PrimalScript 2016 version 7.2.92
32 or 64 bit version of product:
Operating system: Win7
32 or 64 bit OS: 64

Hi
I have written a bunch of stuff which seems to work fine. This is just manipulating data in csv files.
I have built the script into an EXE file which also works fine for me on my system.
When my client runs it it fails. She has a Win7 x32 bit setup. I have the Platform set at "Local Machine 32 Bit"
I suspect it has something to do with the execution policy of the machine as she can run it via a .cmd fine with command line [c:\windows\...powershell.exe -ExecutionPolicy Bypass <filepath and name>.ps1]
Is there a way to set that execution policy in the build so that the script content is not exposed?

Thanks
Wayne
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Setting ExecutionPolicy when building a script

Post by Alexander Riedel »

Depending on the packaging options, the execution policy has usually no effect. We would need to know which exact packaging options you used, which powershell version is on the target system and what "fails" actually means. If there is any error message, please post the message here.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
wayne_Avery
Posts: 30
Last visit: Tue Feb 01, 2022 2:25 pm

Re: Setting ExecutionPolicy when building a script

Post by wayne_Avery »

Hi,
I could not see the error message as it popped in and out too fast. The clients PC is running Powershell version 4. The default execution policy is Restricted.
Today I set the execution policy to Unrestricted and had the client try again. The script now works for them. I am however still interested in finding out how to overcome this in the future.

When I build the package I have the following packager settings set.

Engine Type: Microsoft Windows PowerShell (Command line) Win32
Generate config file: checked
Manifest: Embed a default manifest
Run Mode: Current User

There is nothing else set.
Thanks
Wayne
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Setting ExecutionPolicy when building a script

Post by Alexander Riedel »

This particular engine uses a temporary file, so the execution policy is in effect.
When you say "popped in and out too fast" I assume you launched the exe from something else than a console.
Try launching the exe from a console so you see console output.

You can use a SAPIEN PowerShell Host engine to execute your script in memory and without being affected by execution policy.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 7 years and 6 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.