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 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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
wayne_Avery
Posts: 27
Joined: Mon Sep 27, 2010 12:43 pm

Setting ExecutionPolicy when building a script

Post by wayne_Avery » Thu Sep 01, 2016 10:34 pm

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: 7000
Joined: Tue May 29, 2007 4:43 pm

Re: Setting ExecutionPolicy when building a script

Post by Alexander Riedel » Fri Sep 02, 2016 1:52 am

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: 27
Joined: Mon Sep 27, 2010 12:43 pm

Re: Setting ExecutionPolicy when building a script

Post by wayne_Avery » Sun Sep 04, 2016 4:29 pm

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: 7000
Joined: Tue May 29, 2007 4:43 pm

Re: Setting ExecutionPolicy when building a script

Post by Alexander Riedel » Mon Sep 05, 2016 12:00 pm

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.