Eliminate powershell profile and execution policy related errors

Expected Behavior

When the powershell profile contains code that throws an error photostructure should be able to start as profiles should not be loaded.
Also when powershell execution policy is set to “restricted” photostrucutre should ignore execution policy and start regardless.

Current Behavior

Photostrucutre throws an error upon startup.

Steps to Reproduce profile error

  1. Add powershell profile with an error ie “1/0” by running “notepad $profile” and adding the text “1/0”. This will generate a divisable by zero exception.
  2. Start photostructure, throws error

Steps to Reproduce execution policy error

  1. Run Set-Executionpolicy restricted from an elevated powershell
  2. Start photostructure, throws error

Environment

Windows Server 2019, but equally applicable to Windows 7 and up

Photostructure 0.91 Windows

Suggested solution

Photostrucutre should start all powershell processes with the following arguments
-noprofile -executionpolicy bypass
ie powershell.exe -noprofile -executionpolicy bypass

The -noprofile argument instructs the powershell process to ignore user created profiles. These profiles should not be needed by photostructure.

The -executionpolicy bypass arguments instructs powershell to run the powershell process with executionpolicy bypass.

Please note: It might sound strange to be able to ignore execution policy by providing a executable argument but executionpolicy is a badly named function by Microsoft. It is not intended to stop someone from running scripts that “wants” to run a script. Rather it is a function that prevents end users from running scripts by mistake, ie when they do not intend to run a script, executionpolicy can stop a user that accedentally double-clicked a ps1 file for instance. If the user intends to run a script execution policy can be bypassed in a number of ways that does not require admin-privilegies. Therefor the option exists to start a powershell process that bypasses the executionpolicy.

Powershell commandline arguments is documented here

Execution policy functionality is documented here

Snippet from MS documentation
“The execution policy isn’t a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally.”

Kind regards
Hannes

Welcome to PhotoStructure, and thanks for the suggestion!

I’ve just added this setting to v1.0.0 which will address this issue:

# +------------------+
# |  powerShellArgs  |
# +------------------+
#
# The following are the default arguments added to spin up PowerShell on
# Windows devices.
# See
# <https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1>
# for all arguments that PowerShell.exe accepts.
# See
# <https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-5.1>
# for a description of Bypass.
# See
# <https://forum.photostructure.com/t/eliminate-powershell-profile-and-execution-policy-related-errors/184>
# for more details about why this needs to be configurable.
# (Versions prior to v1.0.0 only specified "-NoLogo").
#
# PS_POWER_SHELL_ARGS="[\"-NoLogo\",\"-NoProfile\",\"-ExecutionPolicy\",\"Bypass\"]"

That was fast :slight_smile:

Thank you!

May I ask how far away 1.0.0 is aprox? Dying to get the new HEIC functionality. :slight_smile:

Of course you can ask! The past couple days I’ve been fighting CI, trying to get my m1 Mac and new docker builds to pass. I also need to finish adding support for hide and delete: most of the backend is done for that already.

I unfortunately tend to be ridiculously optimistic with ETAs, but I really want to have v1.0 out by end of January. The actual release will be preceded by at least a week or two of alpha and beta pre-releases, so if you’re willing to try those, you’ll get HEIF support a bit sooner.