Forum Discussion
Powershell script is not working using PSF
- Jul 21, 20221) The PsfScriptLauncher.ps1 file is missing from the root of the package. This file is part of the PSF. This file is required as it will be executed in PowerShell to then run your script.
2) The timeout value in the Json is too low. The 10 represents 10ms which is generally not long enough for PowerShell to even start up. Increase to 10000 to get 10 seconds, for example.
3) Add a sleep to the end of the powershell start-sleep 60 would give you time to see any error messages in the PowerShell window should they occur. If so, the timeout value will have to increase more.
4) The Unrestricted option in the json will cause a problem if there is any GPO setting the PowerShell restriction policy. As is in your ps1 file, the Bypass option might be a better choice
5) If you still have issues, use the Sysinternals DebugView tool which can display debugging information emitted by the PsfLauncher as it tries to start your script. Start that tool, then launch the shortcut.
so you mean i can remove the set-executionplicy from my script and add the line scriptExecutionMode: to my config.json?
thanks
- Sep 14, 2023
sebastianpehlke Yes there is a way to accomplish what you need.
Generally, you can't write to the WindowsApps area, but you can instead write to the redirection area that the PSF file-based fixups (FileRedirectionFixup or MfrFixup) generally use. Even without the file-based fixups in use in your package, the MSIX runtime will then find the VFS redirected files for Program Files and Windows.
The scripting engine provides two pseudo-variables to help you in specifying the file locations as arguments to your scripts. %MsixPackageRoot% specifies the package folder under WindowsApps (which helps when you change package versions you don't need to edit that). %MsixWritablePackageRoot% specifies the package folder under %LocalAppData%\Packages for this package (which is the version independent redirection area). You can read more about this on the wiki page PsfLauncher · TimMangan/MSIX-PackageSupportFramework Wiki · GitHub
Note that these pseudo-variables are referenced in the config.json file "Arguments" field and are passed into your script after they are dereferenced by Psflauncher.
- sebastianpehlkeSep 14, 2023Copper ContributorSounds good. i solved it but now i have another Problem and dont know if this is possible.
i need to copy a file from the "C:\Program Files\WindowsApps\10-****-556_7.3.0.0_x64__c7rwcv5qq3b5y" into "C:\Program Files\WindowsApps\10-****-556_7.3.0.0_x64__c7rwcv5qq3b5y\VFS\ProgramFilesX86\REDISwin" if a special requirement is true. I´ve added a script (ps1) and all required psf files, changed the manifest (target: psflauncher32.exe). But when i start the application the ps1 failes with the message:
Copy-Item : Access to the path 'C:\Program
Files\WindowsApps\10-****-556_7.3.0.0_x64__c7rwcv5qq3b5y\VFS\ProgramFilesX86\REDISwin\ErrorHandler.config' is denied.
At C:\Program Files\WindowsApps\10-****-556_7.3.0.0_x64__c7rwcv5qq3b5y\CC_StagesConfig.ps1:7 char:1
+ Copy-Item $sourcepath"\PU_ErrorHandler.config" -destination $targetpa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Program File...rHandler.config:FileInfo) [Copy-Item], Unauthorized
AccessException
+ FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
is there a way to handle that?
thanks for your help and have a nice afternoon.