[Bug] Activesetup not applying for current logged on user
Prerequisites
- [X] Ensure you write a short, descriptive title after [Bug] above.
- [X] Make sure to search for any existing issues before filing a new one.
- [X] Verify you are able to reproduce the issue with the latest released version
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
Possibly it is working with the user account and not the system account because when running it with system account, it is zone 0.
I will backtrack to 3.9.3 until it is resolve but if I may help then I will be happy.
Related issue posted here: https://www.reddit.com/r/PSADT/comments/1d6l5xz/active_setup_task_scheduler_ending_with_0_but_did/
Was someone able to reproduce the issue?
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?
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?
3.10.1
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.
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:
/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:
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
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.
@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
@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?
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.