Skip to content

Commit

Permalink
Issues 95, 141, 152, 159, 168, and 169, and 171 (#170)
Browse files Browse the repository at this point in the history
* Don't throw error to user when shell launch returns non-zero, just log it.

* Fix Issue #95

* Fix Issue 141 - Don't set CreationFlags if no attributeList

* FIx Issue 152 - Find PowerShell.exe fix

* Fix Issue 168 - Handle DllFixup with full path passed in.

* Issue 169 - Add Fixup for SetCurrentDirectory in FRF

* Fix Issue 169 - Add SerWorkingDirectory to FRF

* Fix Issue 169 - Added SetWOrkingDirectory.cpp to project.

* Fix Issue 171 - waitForDebugger in PsfLauncher debug build.

* Review updates

* REview Comments
  • Loading branch information
TimMangan committed Jan 25, 2021
1 parent c935a9b commit 517cd2f
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 356 deletions.
11 changes: 10 additions & 1 deletion PsfLauncher/PsfPowershellScriptRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,16 @@ class PsfPowershellScriptRunner
}
else if (createResult != ERROR_SUCCESS)
{
THROW_HR_MSG(HRESULT_FROM_WIN32(createResult), "Error with getting the key to see if PowerShell is installed.");
// Certain systems lack the 1 key but have the 3 key (both point to same path)
createResult = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\PowerShell\\3", 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_READ, nullptr, &registryHandle, nullptr);
if (createResult == ERROR_FILE_NOT_FOUND)
{
return false;
}
else if (createResult != ERROR_SUCCESS)
{
THROW_HR_MSG(HRESULT_FROM_WIN32(createResult), "Error with getting the key to see if PowerShell is installed.");
}
}

DWORD valueFromRegistry = 0;
Expand Down
6 changes: 5 additions & 1 deletion PsfLauncher/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Based on the manifest's application ID, the `psfLauncher` looks for the app's la

PSF Launcher also supports running an additional "monitor" app, intended for PsfMonitor. You use PsfMonitor to view the output in conjuction with TraceFixup injection configured to output to events.

Finally, PsfLauncher also support some limited PowerShell scripting.

## Configuration
PSF Launcher uses a config.json file to configure the behavior.

Expand Down Expand Up @@ -244,7 +246,9 @@ This example shows an alternative for the json used in the prior example. This m
In this example, the pseudo-variable %MsixPackageRoot% would be replaced by the folder path that the package was installed to. This pseudo-variable is only available for string replacement by PsfLauncher in the arguments field. The example shows a reference to a file that was placed at the root of the package and another that will exist using VFS pathing. Note that as long as the LOCALAPPDATA file is the only file required from the package LOCALAPPDATA folder, the use of FileRedirectionFixup would not be mandated.

### Example 4
This example shows an alternative for the json used in the prior example. This might be used when an additional script is to be run upon first launch of the application. Such scripts are sometimes used for per-user configuration activities that must be made based on local conditions.
This example shows an alternative for the json used in the prior example. This might be used when an additional script is to be run upon first launch of the application. Such scripts are sometimes used for per-user configuration activities that must be made based on local conditions.

To implement scripting PsfLauncher uses a PowerShell script as an intermediator. PshLauncher will expect to find a file StartingScriptWrapper.ps1, which is included as part of the PSF, to call the PowerShell script that is referenced in the Json. The wrapper script should be placed in the package as the same folder used by the launcher.


```json
Expand Down
9 changes: 7 additions & 2 deletions PsfLauncher/StartProcessHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ HRESULT StartProcess(LPCWSTR applicationName, LPWSTR commandLine, LPCWSTR curren
PROCESS_INFORMATION processInfo{};

startupInfoEx.lpAttributeList = attributeList;

DWORD CreationFlags = 0;
if (attributeList != NULL)
{
CreationFlags = EXTENDED_STARTUPINFO_PRESENT;
}

RETURN_LAST_ERROR_IF_MSG(
!::CreateProcessW(
applicationName,
commandLine,
nullptr, nullptr, // Process/ThreadAttributes
true, // InheritHandles
EXTENDED_STARTUPINFO_PRESENT, // CreationFlags
CreationFlags,
nullptr, // Environment
currentDirectory,
(LPSTARTUPINFO)&startupInfoEx,
Expand Down
Loading

0 comments on commit 517cd2f

Please sign in to comment.