Writing to HKCU after app as run during install

Hi,

It isnt PSADT related as such but was wondering if anyone has encountered a similar scenario and if they got around it with PSADT.

Ive got an app where the HKCU hive does not populate until the actual app has been run by the user after installation but I need to change a specific setting.

Changing the reg setting Post Install as normal will be overwritten once the application has run.

Not sure how to get around this... Does anyone have any ideas?

I have an idea, but unsure if it'll work

  • During the post install section, launch the app (silently or hidden if possible) - You may need to unblock the app launch if you had configured this during the install.
  • Wait a period of time until the expected registry changes have been populated
  • Close the App (confirm it has successfully closed)
  • Modify the Registry key how you would like it
  • Let the PSADT script complete

How you code this would be a fun exercise I'm sure :grin:

2 Likes

Another idea is to populate enough of the registry to fool the app to think it has run already.
This should to stop it from overwriting the registry changes you want.

But this is guess work and Adrian's solution has a better chance of success.

Yeah... this app is a pain. Needs to run as the user but this cant be done if the installation is in system context.

Error Record:
-------------
 
Message               : Exception calling "LaunchAsync" with "1" argument(s): "The requested operation requires elevation"
InnerException        : System.ComponentModel.Win32Exception (0x80004005): The requested operation requires elevation
                           at PSADT.LibraryInterfaces.AdvApi32.CreateProcessAsUser(SafeHandle hToken, String lpApplicationName, Span`1& lpCommandLine, Nullable`1 lpProcessAttributes, Nullable`1 lpThreadAttributes, BOOL bInheritHandles, PROCESS_CREATION_FLAGS dwCreationFlags, SafeEnvironmentBlockHandle lpEnvironment, String lpCurrentDirectory, STARTUPINFOW& lpStartupInfo, PROCESS_INFORMATION& lpProcessInformation) in D:\a\PSAppDeployToolkit\PSAppDeployToolkit\src\PSADT\PSADT\LibraryInterfaces\AdvApi32.cs:line 285
                           at PSADT.ProcessManagement.ProcessManager.CreateProcessUsingToken(SafeFileHandle hPrimaryToken, String filePath, Span`1& commandLine, Boolean inheritHandles, Boolean callerUsingHandles, PROCESS_CREATION_FLAGS creationFlags, SafeEnvironmentBlockHandle lpEnvironment, String workingDirectory, STARTUPINFOW& startupInfo, PROCESS_INFORMATION& pi) in D:\a\PSAppDeployToolkit\PSAppDeployToolkit\src\PSADT\PSADT\ProcessManagement\ProcessManager.cs:line 738
                           at PSADT.ProcessManagement.ProcessManager.LaunchAsync(ProcessLaunchInfo launchInfo) in D:\a\PSAppDeployToolkit\PSAppDeployToolkit\src\PSADT\PSADT\ProcessManagement\ProcessManager.cs:line 165
                           at CallSite.Target(Closure , CallSite , Type , Object )
 
FullyQualifiedErrorId : Win32Exception,Start-ADTProcess
ScriptStackTrace      : at Start-ADTProcess<Process>, C:\Packages\Intune files\Fiddler5\content\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 22246
                        at Start-ADTProcessAsUser<Process>, C:\Packages\Intune files\Fiddler5\content\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 22844
                        at Install-ADTDeployment, C:\Packages\Intune files\Fiddler5\content\Invoke-AppDeployToolkit.ps1: line 227
                        at <ScriptBlock>, C:\Packages\Intune files\Fiddler5\content\Invoke-AppDeployToolkit.ps1: line 431
                        at <ScriptBlock>, <No file>: line 1
 
PositionMessage       : At C:\Packages\Intune files\Fiddler5\content\PSAppDeployToolkit\PSAppDeployToolkit.psm1:22844 char:20
                        + ...      return & $Script:CommandTable.'Start-ADTProcess' @PSBoundParamet ...
                        +    

seem to get the above error when running the cmd below:

## main installation
    Write-ADTLogEntry -Message "Installing $($adtsession.appvendor, $adtsession.appname, $adtsession.appversion)"
    start-adtprocessasuser -FilePath "FiddlerSetup.exe" `
    -ArgumentList "/S" `
    -WindowStyle Hidden

This is running in a elevated cmd prompt as system as well.

Ah Fiddler!

Are you by any chance trying the registry changes mentioned in the Fiddler Classic instructions found here:

?

As this needs to be run with Admin rights then maybe the registry addition needs to be carried out using Start-ADTProcessAsUser

N.B. I think the Fiddler Setup needs to be run with Admin rights (suggest System), then make the Registry changes as the user using Start-ADTProcessAsUser

Just found this:

Depending on the version of Fiddler you are trying to install, it may not be possible to what you are doing. Who thought it was a good idea to install an app as a user when the app needs admin rights, don't they know most (corporate) users don't have admin rights :exploding_head:

2 Likes

Exactly! Dont get why vendors/developers do this so often and with this one, people have complained since 2019!

You could copy the .exe to somewhere on the device and give admin to that directory to run and then delete once done... I could try that... then try the reg settings (I only want to stop autoupdate check so it isnt a massive issue if i cannot).

The only other way around this is to run this as system:

FiddlerSetup.exe /S /D=%ProgramFiles%\Fiddler

And then physically create shortcut pointing to the .exe as it doesnt install for every user just the system user, but this may stop certain extensions for the app to run so I have read.

1 Like

Maybe try this as an alternative deployment method

 
FullyQualifiedErrorId : PathNotFound,Repair-ADTWinGetPackageManager
ScriptStackTrace      : at Get-ADTWinGetPath, C:\Packages\Intune files\Fiddler5\content\PSAppDeployToolkit.WinGet\PSAppDeployToolkit.WinGet.psm1: line 1394
                        at Repair-ADTWinGetPackageManager<Process>, C:\Packages\Intune files\Fiddler5\content\PSAppDeployToolkit.WinGet\PSAppDeployToolkit.WinGet.psm1: line 3609
                        at Install-ADTDeployment, C:\Packages\Intune files\Fiddler5\content\Invoke-AppDeployToolkit.ps1: line 226
                        at <ScriptBlock>, C:\Packages\Intune files\Fiddler5\content\Invoke-AppDeployToolkit.ps1: line 435
                        at <ScriptBlock>, <No file>: line 1
 
TargetObject          : C:\Program Files (x86)\WindowsApps
 
PositionMessage       : At C:\Packages\Intune files\Fiddler5\content\Invoke-AppDeployToolkit.ps1:226 char:5
                        +     Repair-ADTWinGetPackageManager -Verbose

Seem to keep getting this error when trying to install a winget app via psadt.