PSAppDeployToolkit icon indicating copy to clipboard operation
PSAppDeployToolkit copied to clipboard

[Bug] Activesetup not applying for current logged on user

Open FRacine opened this issue 1 year ago • 5 comments

Prerequisites

PSAppDeployToolkit version

3.10.1

Describe the bug

This was working previously: wscript.exe "C:\Users\Public\PSAppDeployToolkit\PSAppDeployToolkit-ExecuteAsUser.vbs"

Our active setup file is there:C:\Program Files\Organisation\InstTrousses\Trousses\WinSCP6_Frv1\ActiveSetup\ActiveSetup.ps1 Manually it is working. Running the whole product installation under a loggedon user with a runas admin is working correctly Under the system account it is not working.

Steps to reproduce

1.Open an admnisitrator command window 2. Using psexec, run psexec -s -i cmd.exe 3.Start powershell 4. Run the script

5. **Set-ActiveSetup -StubExePath "$var_ActiveSetup83" -Description "Configuration de $var_PackageLongName" -Key "$var_PackageLongName" -Locale 'Fr'**

$var_ActiveSetup83
C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1

"Configuration de $var_PackageLongName"
Configuration de WinSCP6_Frv1

"$var_PackageLongName" 
WinSCP6_Frv1

7. =====================
**From function: Set-ActiveSetup**
Execute-ProcessAsUser -Path $CUStubExePath -Parameters $CUArguments -Wait -ContinueOnError $true

$CUStubExePath
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

$CUArguments
-ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -Command "& {& \"C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1\"}"
=====================

8. =====================
**Function Execute-ProcessAsUser**
[PSObject]$schTaskResult = Execute-Process -Path $exeSchTasks -Parameters "/create /f /tn $schTaskName /xml `"$xmlSchTaskFilePath`"" -WindowStyle 'Hidden' -CreateNoWindow -PassThru -ExitOnProcessFailure $false

$exeSchTasks
C:\WINDOWS\System32\schtasks.exe

$xmlSchTaskFilePath
C:\WINDOWS\TEMP\PSAppDeployToolkit\PSAppDeployToolkit-ExecuteAsUser-001.xml
=====================

9. =====================
Ending in task scheduler as:
C:\WINDOWS\System32\wscript.exe /e:vbscript C:\WINDOWS\TEMP\PSAppDeployToolkit\ExecuteAsUser\RunHidden.vbs C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -Command "& {& \"C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1\"}"
=====================

Running the task scheduler commandline manually with the system account is making the script result as not applying. Starting the task scheduler manually is not getting the result expected. The Task is ending with 0 but the script did not ran.

Environment data

Windows 10
22H2
64 bits Pro French
19045.4412

FRacine avatar May 23 '24 15:05 FRacine

Possibly it is working with the user account and not the system account because when running it with system account, it is zone 0.

FRacine avatar May 23 '24 18:05 FRacine

I will backtrack to 3.9.3 until it is resolve but if I may help then I will be happy.

FRacine avatar May 23 '24 18:05 FRacine

Related issue posted here: https://www.reddit.com/r/PSADT/comments/1d6l5xz/active_setup_task_scheduler_ending_with_0_but_did/

DanGough avatar Jun 08 '24 21:06 DanGough

Was someone able to reproduce the issue?

FRacine avatar Jun 20 '24 11:06 FRacine

I put these commands in a deployment script and ran it as system via SCCM:

Execute-ProcessAsUser -Path 'C:\Windows\Notepad.exe'
Set-ActiveSetup -Key 'PSADT_Test' -Version '1,0' -StubExePath 'C:\WINDOWS\system32\mspaint.exe'

Both Notepad and Paint came up in user context. Please can you let us know if these simple commands produce a visible application in user context from a system installation?

DanGough avatar Jul 04 '24 23:07 DanGough

I put these commands in a deployment script and ran it as system via SCCM:

Execute-ProcessAsUser -Path 'C:\Windows\Notepad.exe'
Set-ActiveSetup -Key 'PSADT_Test' -Version '1,0' -StubExePath 'C:\WINDOWS\system32\mspaint.exe'

Both Notepad and Paint came up in user context. Please can you let us know if these simple commands produce a visible application in user context from a system installation?

With which toolkit?

FRacine avatar Jul 05 '24 10:07 FRacine

3.10.1

DanGough avatar Jul 05 '24 11:07 DanGough

It is a lot easier working with psexec -s -i cmd.exe At this point you are in system with session 0. This is the most important as in session 0, the script will be using the task scheduler.

You are launching an Exe and its working. This is as on line 8295 of the main script the commandline is very simple. You are just launching an exe. Scheduletask exe

The run: Set-ActiveSetup -StubExePath "C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1" -Description "Configuration de WINSCP" -Key "WinSCP6_Frv1" -Locale 'Fr' The commandline will now be much complicated: TaskSchedulerwithPs1

/e:vbscript C:\WINDOWS\TEMP\PSAppDeployToolkit\ExecuteAsUser\RunHidden.vbs C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -Command "& {& \"C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1\"}"

And this is not working.

The old way was: OldActivesetup And its working.

strCommand = chr(34) & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" & chr(34) & " -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -Command " & chr(34) & "& {& \" & chr(34) & "C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1\" & chr(34) & "}" & chr(34)
set oWShell = CreateObject("WScript.Shell")
intReturn = oWShell.Run(strCommand, 0, true)
WScript.Quit intReturn

FRacine avatar Jul 05 '24 13:07 FRacine

Ok, that narrows it down that it only happens when passing it a .ps1.

Whenever I have used active setup to run a ps1 in the past, I have given it the stubpath to run powershell directly, with -File <scriptpath>. For example:

Set-ActiveSetup -StubExePath "$envSystem32Directory\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -File C:\PROGRA~1\ORGANI~1\INSTTR~1\Trousses\WINSCP~1\ACTIVE~1\ACTIVE~1.PS1" -Description "Configuration de WINSCP" -Key "WinSCP6_Frv1" -Locale 'Fr'

It appears that the toolkit is trying to be helpful here and hide the script for you, but breaking something in the process - I will see if I can reproduce and fix if so.

DanGough avatar Jul 05 '24 15:07 DanGough

@FRacine I have a branch here with proposed fixes, I'd be grateful if you could give it a test!

https://github.com/PSAppDeployToolkit/PSAppDeployToolkit/tree/DanGough/issue999

DanGough avatar Jul 07 '24 01:07 DanGough

@FRacine I have a branch here with proposed fixes, I'd be grateful if you could give it a test!

https://github.com/PSAppDeployToolkit/PSAppDeployToolkit/tree/DanGough/issue999

I confirm it is working. What did you changed exactly? Using WScript instead CScript? What does it change?

FRacine avatar Jul 08 '24 12:07 FRacine

Thanks - PR is here with further info: https://github.com/PSAppDeployToolkit/PSAppDeployToolkit/pull/1017

File changes are here: https://github.com/PSAppDeployToolkit/PSAppDeployToolkit/pull/1017/files

The cscript->wscript change won't affect your use case, it will just ensure that vbscripts are hidden just like .ps1/.cmd scripts are.

DanGough avatar Jul 08 '24 12:07 DanGough