SOLVED

Issues with PowerShell start and end scripts

Copper Contributor

I think there is a problem with the PSFLauncher.exe. It appears to be using the working directory of the application shortcut to find the StartingScriptWrapper.ps1. This is breaking PowerShell support in PSFTooling and Advanced Installer Express. Is this expected behavior? I can think of lots of reasons not to have things working this way. 

11 Replies
@Skinheed

Thank you for posting in our forums. Thank you for bringing up this issue with PSF. The expected behavior for Powershell scripts is the root of the application directory, not the directory of the shortcut. This is an issue with PSF and would need to be fixed.

Can you please make an issue on the MSIX_PackageSupportFramework github repo here: https://github.com/microsoft/MSIX-PackageSupportFramework/issues. This is where all the issues for PSF are being tracked.

Thanks,

Darren.
best response confirmed by Skinheed (Copper Contributor)
Solution

Hi @Skinheed 

 

I am Bogdan, from the Advanced Installer team. Thanks for reporting this issue. Just wanted to let you know that until a fix is included by MSFT in the official PSF repo we will include a custom fix directly inside our next version.

 

Until then, you have a workaround in Advanced Installer:


Advanced Installer allows you to update the working directory and application parameters (that you would usually specify in the "Application Details" view) directly from the PS1 script.

For your scenario, please follow these steps.

  1. Go to "Application Details > Working directory" and make sure this field (Working Directory) is empty.
  2. Use a PS script that updates the Working directory, attached is a sample.

This sample PS script (from the attached zip) updates the Working directory to the first argument it receives (its value should be relative to APPDIR).

IMPORTANT, when using the above script:

  1. change the script to include your own ApplicationID.
  2. set the desired working directory path (relative to APPDIR) in the 'scriptArguments' field.
    The Working Dir argument can also be changed directly from inside your PS1 script, if you wish to hardcode it inside the script.
  3. set the 'waitForScriptToFinish' field to 'true'

    Let me know if this helps.

Darren,

I have gotten the same issue/request from another customer. PsfTooling is unable to place the file at the root folder since it doesn't exist yet. A modification to the launching code will be needed to allow for this case. It's actually a lot like the config.json file location issue I previously fixed. TMEditX does add these to the root folder of the package so it doesn't have this problem with scripts.
Hi Bogdan,

I have had a chance to test this out and the PowerShell script is still not being executed. Running Procmon I see no PowerShell process at all, only the AIStub.exe which is finding my script file in the application root. I don't think the StartingScriptWrapper.ps1 is running either, I cant find any reference to it in Procmon. The application starts with no error it just doesn't run the script and I see no PowerShell window even though I have set it to show.
I'm not 100% sure this isn't a config issue. Can you show the Json file? I would also recommend that you use SysInternals DebugView for debugging this type of issue. The PsfLauncher code that handles the scripts outputs the information you need to see about script launching to the debug console.
Hi Tim,

Here is config.json from the Advanced installer package. I did manage to get it working with the PSFTooling after changing the config.json to use a relative path.

{
"processes": [
{
"executable": ".*",
"fixups": [
{
"dll": "FileRedirectionFixup",
"config": {
"redirectedPaths": {
"packageRelative": [
{
"base": "program",
"patterns": [
"__pycache__"
]
},
{
"base": "program\\python-core-3.5.7\\lib",
"patterns": [
".*"
]
},
{
"base": "share\\extensions\\dict-en\\pythonpath",
"patterns": [
"__pycache__"
]
},
{
"base": "share\\uno_packages",
"patterns": [
".*"
]
}
]
}
}
},
{
"dll": "AiShims",
"config": {
"dllDirectory": [
""
]
}
},
{
"dll": "CreateProcShim",
"config": {
"redirectedPaths": {}
}
},
{
"dll": "TraceFixup",
"config": {}
}
]
}
],
"applications": [
{
"id": "LibreOffice",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOfficeWriter",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOfficeCalc",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOfficeDraw",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOfficeMath",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOfficeImpress",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
},
{
"id": "LibreOffice1",
"startScript": {
"scriptArguments": "-Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program",
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
},
"endScript": {
"showWindow": true,
"waitForScriptToFinish": true,
"scriptPath": "Roam.ps1",
"timeout": 3000
}
}
]
}

Thanks for the DebugView tip I will try that out now.
Hi Tim,

I get the following in DebugView:

[4132] StartingScript commandString=Powershell.exe -file StartingScriptWrapper.ps1 "Powershell.exe -file '.\Roam.ps1' -Start -AppIDs LibreOffice,LibreOffice1,LibreOfficeClalc,LibreOfficeDraw,LibreOfficeImpress,LibreOffice,LibreOfficeMath,LibreOfficeWriter -WDSubDir Program"
[4132] StartingScript currentDirectory=C:\Program Files\WindowsApps\LibreOffice.org.LibreOffice_6.2.8.0_x64__6pj9mnfdq70vt
[4132] StartingScript waitForScriptToFinish=true

It looks correct but still no PowerShell process appearing in Procmon while capturing the debug output. I would use my PSFTooling package that I have fixed but I can't get the MSPT to accept the package manifest after adding the fonts captured by PSFTooling.
PsfTooling provides you text to copy into the manifest, but must do so before the manifest exists so we had to guess how much to provide. It provides the minimal syntax that works for many packages, but depending on what else is in the package there may need to be more editing of the manifest to make the schema happy. For example, your package application may or may not have an <Application><Extensions> element to place the uap4:Extension into. But most of the time people have trouble because the app didn't reference the schema needed (UAP4) at the top of the file.

But even with what you have in AdvancedInstaller, if you just add a extra copy of the StartingScriptWrapper.ps1 into the working directory for the application you'll be fine. This is, essentially what PsfTooling is doing.

Hi @Skinheed,

 

I've published an update for AI Express in the store today (it should pass MS validation in a few hours). 

 

Download this update and try the old project. It should not require the workaround I suggested in my previous answer.

 

Cheers,

Bogdan

Hi Bogdan,

Thanks for the update. I did manage to get an RC version from your support team and the issue is fixed.

Thanks for your help

Craig
FYI (In case anyone runs into this issue) A fix for the issue is now up in my fork of the PSF. I'll be scheduling a pull request into the Microsoft develop branch soon.
1 best response

Accepted Solutions
best response confirmed by Skinheed (Copper Contributor)
Solution

Hi @Skinheed 

 

I am Bogdan, from the Advanced Installer team. Thanks for reporting this issue. Just wanted to let you know that until a fix is included by MSFT in the official PSF repo we will include a custom fix directly inside our next version.

 

Until then, you have a workaround in Advanced Installer:


Advanced Installer allows you to update the working directory and application parameters (that you would usually specify in the "Application Details" view) directly from the PS1 script.

For your scenario, please follow these steps.

  1. Go to "Application Details > Working directory" and make sure this field (Working Directory) is empty.
  2. Use a PS script that updates the Working directory, attached is a sample.

This sample PS script (from the attached zip) updates the Working directory to the first argument it receives (its value should be relative to APPDIR).

IMPORTANT, when using the above script:

  1. change the script to include your own ApplicationID.
  2. set the desired working directory path (relative to APPDIR) in the 'scriptArguments' field.
    The Working Dir argument can also be changed directly from inside your PS1 script, if you wish to hardcode it inside the script.
  3. set the 'waitForScriptToFinish' field to 'true'

    Let me know if this helps.

View solution in original post