Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/playbook/Configuration/atlas/revert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ actions:
- !writeStatus: { status: "Reverting old changes" }
- !run:
exe: "%windir%\\AtlasModules\\Tools\\StoreFixer.exe"
args: "silent"
args: "silent isSetScheduledTaskOnCrash noRestart"
weight: 2
wait: true
exeDir: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
@echo off
cd /d "%~dp0"
echo Current directory: %cd%
echo Looking for: %cd%StoreFixer.exe
setlocal EnableDelayedExpansion

if not exist "StoreFixer.exe" (
echo Running as Trusted Installer

if not exist "%windir%\AtlasModules\Tools\StoreFixer.exe" (
echo ERROR: StoreFixer.exe not found!
echo Please ensure StoreFixer.exe is in the same directory as this script.
pause
exit /b 1
)
if "%~1"=="/silent" (
call RunAsTI.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" silent -wait
echo Running StoreFixer.exe silently...
call RunAsTi.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" silent -wait
exit 0
)

call RunAsTI.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" -wait
echo Running StoreFixer.exe...
RunAsTi.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" -wait
echo StoreFixer.exe completed.
pause
192 changes: 73 additions & 119 deletions src/playbook/Executables/AtlasModules/Scripts/RunAsTI.cmd
Original file line number Diff line number Diff line change
@@ -1,84 +1,77 @@
<# : batch portion
@echo off
setlocal EnableDelayedExpansion
goto RunAsTI-Elevate

----------------------------------------
[CREDITS]
- Adapted from https://github.com/AveYo/LeanAndMean
- Revised and customized for Atlas by he3als & Xyueta
- Added error checking, an interface and quotes support

[FEATURES]
- Innovative HKCU load, no need for 'reg load' or unload ping-pong; programs get the user profile
- Sets ownership privileges, high priority, and Explorer support; get System if TrustedInstaller is unavailable
- Accepts special characters in paths for which default 'Run as Administrator' fails

[USAGE]
- call RunAsTI.cmd "[executable]" [args (optional)]
- Put this at the top of your script:

whoami /user | find /i "S-1-5-18" > nul 2>&1 || (
call RunAsTI.cmd "%~f0" %*
exit /b
)
----------------------------------------

:RunAsTI-Elevate
if "%~1" == "" (
set /P program_path="Enter the valid path of the program or drag it here: " || (
echo error: no input
timeout /t 3 /nobreak > nul
cls
goto RunAsTI-Elevate
)

call :RunAsTI !program_path!
exit /b 1
)

@REM MIT License

@REM Copyright (c) 2021 AveYo

@REM Permission is hereby granted, free of charge, to any person obtaining a copy
@REM of this software and associated documentation files (the "Software"), to deal
@REM in the Software without restriction, including without limitation the rights
@REM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@REM copies of the Software, and to permit persons to whom the Software is
@REM furnished to do so, subject to the following conditions:

@REM The above copyright notice and this permission notice shall be included in all
@REM copies or substantial portions of the Software.

@REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@REM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@REM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@REM AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@REM LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
@REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
@REM SOFTWARE.

@REM Software provided under MIT license
@REM https://github.com/AveYo/LeanAndMean
@REM Version of the script as of commit `b0782ef`
@REM https://github.com/AveYo/LeanAndMean/tree/b0782ef281d64a3dda086de7bada1c02decc7cf9


@echo off& title RunAsTI - lean and mean snippet by AveYo, 2018-2022
goto :nfo
[FEATURES]
- innovative HKCU load, no need for reg load / unload ping-pong; programs get the user profile
- sets ownership privileges, high priority, and explorer support; get System if TI unavailable
- accepts special characters in paths for which default run as administrator fails
- adds Send to - RunAsTI right-click menu entry to launch files and folders as TI via explorer
[USAGE]
- First copy-paste RunAsTI snippet after .bat script content
- Then call it anywhere to launch programs with arguments as TI
call :RunAsTI regedit
call :RunAsTI powershell -noprofile -nologo -noexit -c [environment]::Commandline
call :RunAsTI cmd /k "whoami /all & color e0"
call :RunAsTI "C:\System Volume Information"
- Or just relaunch the script once if not already running as TI:
whoami /user | findstr /i /c:S-1-5-18 >nul || ( call :RunAsTI "%~f0" %* & exit /b )
2022.01.28: workaround for 11 release (22000) hindering explorer as TI; fix 7 args
2023.07.06 fix arguments with quotes
:nfo

:::::::::::::::::::::::::
:: .bat script content ::
:::::::::::::::::::::::::

:: [optional] add Send to - RunAsTI right-click menu entry to launch files and folders as TI via explorer
set "0=%~f0"& powershell -nop -c iex(([io.file]::ReadAllText($env:0)-split':SendTo\:.*')[1])& goto :SendTo:
$SendTo=[Environment]::GetFolderPath('ApplicationData')+'\Microsoft\Windows\SendTo\RunAsTI.bat'; $enc=[Text.Encoding]::UTF8
if ($env:0 -ne $SendTo) {[IO.File]::WriteAllLines($SendTo, [io.file]::ReadAllLines($env:0,$enc))}
:SendTo:

:: call RunAsTI snippet with default commandline args - if none provided, defaults to opening This PC as TI
call :RunAsTI %*
exit /b

:RunAsTI-Declined
echo]
echo Self-elevation to TrustedInstaller failed, because the UAC prompt was declined.
echo Selecting 'Yes' to the UAC prompt is required for this script.
echo]
echo Press any key to attempt to elevate again...
pause > nul
goto RunAsTI-Elevate

:RunAsTI-Fail
echo]
echo Executing the script as TrustedInstaller failed with the RunAsTI snippet.
echo An unknown error has occurred, please report this (with the error) or attempt to elevate again!
echo]
echo Press any key to attempt to elevate again...
pause > nul
goto RunAsTI-Elevate
echo args: %*
::whoami
::timeout /t 7

:RunAsTI
set "_runAsTiArgs=%*"
set "RunAsTI_WindowStyle=Normal"
echo %_runAsTiArgs% | findstr /i /c:"/silent" /c:"-silent" /c:"/quiet" > nul 2>&1 && set "RunAsTI_WindowStyle=Hidden"
if /I not "%RunAsTI_WindowStyle%"=="Hidden" echo Administrator privileges are required.
:: done
exit /b

set "0=%~f0"
set "1=%*"
PowerShell -NoP -c iex(gc """$env:0""" -Raw)
set "RunAsTI_Errorlevel=%ERRORLEVEL%"
if "%RunAsTI_Errorlevel%" == "1" (
goto RunAsTI-Fail
) else (
if "%RunAsTI_Errorlevel%" == "2" (
goto RunAsTI-Declined
) else (
exit /b
)
)
: end batch / begin powershell #>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: .bat script content end - copy-paste RunAsTI snippet ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#:RunAsTI snippet to run as TI/System, with innovative HKCU load, ownership privileges, high priority, and explorer support
set ^ #=& set "0=%~f0"& set 1=%*& powershell -c iex(([io.file]::ReadAllText($env:0)-split'#\:RunAsTI .*')[1])& exit /b
function RunAsTI ($cmd,$arg) { $id='RunAsTI'; $key="Registry::HKU\$(((whoami /user)-split' ')[-1])\Volatile Environment"; $code=@'
$I=[int32]; $M=$I.module.gettype("System.Runtime.Interop`Services.Mar`shal"); $P=$I.module.gettype("System.Int`Ptr"); $S=[string]
$D=@(); $T=@(); $DM=[AppDomain]::CurrentDomain."DefineDynami`cAssembly"(1,1)."DefineDynami`cModule"(1); $Z=[uintptr]::size
Expand All @@ -93,11 +86,11 @@ function RunAsTI ($cmd,$arg) { $id='RunAsTI'; $key="Registry::HKU\$(((whoami /us
function M ($1,$2,$3) {$M."G`etMethod"($1,[type[]]$2).invoke(0,$3)}; $H=@(); $Z,(4*$Z+16)|% {$H += M "AllocHG`lobal" $I $_}
M "WriteInt`Ptr" ($P,$P) ($H[0],$As.Handle); $A1.f1=131072; $A1.f2=$Z; $A1.f3=$H[0]; $A2.f1=1; $A2.f2=1; $A2.f3=1; $A2.f4=1
$A2.f6=$A1; $A3.f1=10*$Z+32; $A4.f1=$A3; $A4.f2=$H[1]; M "StructureTo`Ptr" ($D[2],$P,[boolean]) (($A2 -as $D[2]),$A4.f2,$false)
$Run=@($null, "powershell -windowstyle $env:RunAsTI_WindowStyle -nop -c iex `$env:R; # $id", 0, 0, 0, 0x0E080600, 0, $null, ($A4 -as $T[4]), ($A5 -as $T[5]))
$Run=@($null, "powershell -win 1 -nop -c iex `$env:R; # $id", 0, 0, 0, 0x0E080600, 0, $null, ($A4 -as $T[4]), ($A5 -as $T[5]))
F 'CreateProcess' $Run; return}; $env:R=''; rp $key $id -force; $priv=[diagnostics.process]."GetM`ember"('SetPrivilege',42)[0]
'SeSecurityPrivilege','SeTakeOwnershipPrivilege','SeBackupPrivilege','SeRestorePrivilege' |% {$priv.Invoke($null, @("$_",2))}
$HKU=[uintptr][uint32]2147483651; $NT='S-1-5-18'; $reg=($HKU,$NT,8,2,($HKU -as $D[9])); F 'RegOpenKeyEx' $reg; $LNK=$reg[4]
function L ($1,$2,$3) {sp 'HKLM:\SOFTWARE\Classes\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}' 'RunAs' $3 -force -ea 0
function L ($1,$2,$3) {sp 'HKLM:\Software\Classes\AppID\{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}' 'RunAs' $3 -force -ea 0
$b=[Text.Encoding]::Unicode.GetBytes("\Registry\User\$1"); F 'RegSetValueEx' @($2,'SymbolicLinkValue',0,6,[byte[]]$b,$b.Length)}
function Q {[int](gwmi win32_process -filter 'name="explorer.exe"'|?{$_.getownersid().sid-eq$NT}|select -last 1).ProcessId}
$11bug=($((gwmi Win32_OperatingSystem).BuildNumber)-eq'22000')-AND(($cmd-eq'file:')-OR(test-path -lit $cmd -PathType Container))
Expand All @@ -107,44 +100,5 @@ function RunAsTI ($cmd,$arg) { $id='RunAsTI'; $key="Registry::HKU\$(((whoami /us
if ($11bug) {$w=0; do {if($w-gt40){break}; sleep -mi 250;$w++} until (Q); [Microsoft.VisualBasic.Interaction]::AppActivate($(Q))}
if ($11bug) {[Windows.Forms.SendKeys]::SendWait($path)}; do {sleep 7} while(Q); L '.Default' $LNK 'Interactive User'
'@; $V='';'cmd','arg','id','key'|%{$V+="`n`$$_='$($(gv $_ -val)-replace"'","''")';"}; sp $key $id $($V,$code) -type 7 -force -ea 0
start powershell -args "-windowstyle $env:RunAsTI_WindowStyle -nop -c `n$V `$env:R=(gi `$key -ea 0).getvalue(`$id)-join''; iex `$env:R" -verb runas
} #:RunAsTI lean & mean snippet by AveYo, 2023.07.06

Try {
$initArgs = $env:1
$split = ($initArgs -split ' ')[0]

if ($split -like '*"*') {
$exe = ''; $quoteCount = 0
foreach ($char in $initArgs.ToCharArray()) {
$exe += $char
if ($char -eq '"') {
$quoteCount++
if ($quoteCount -eq 2) {break}
}
}
} else {
$exe = $split
}

$arguments = ($initArgs.Remove(0, $exe.Length)).Trim()

RunAsTI $exe $arguments
}
Catch {
Write-Host ""
$UACDeclined = $PSItem | Select-String -pattern "The operation was canceled by the user" -quiet
if ( $UACDeclined )
{
$exitcode = 2
Write-Host "PowerShell: UAC prompt was declined!" -ForegroundColor Red
}
else {
$exitcode = 1
Write-Host "PowerShell: Failed to self-elevate (unknown error)!" -ForegroundColor Red
Write-Host ""
Write-Host Error: $PSItem -ForegroundColor Red
Write-Host Where: $PSItem.ScriptStackTrace -ForegroundColor Red
}
exit $exitcode
}
start powershell -args "-win 1 -nop -c `n$V `$env:R=(gi `$key -ea 0).getvalue(`$id)-join''; iex `$env:R" -verb runas
}; $A=,$env:1-split'"([^"]+)"|([^ ]+)',2|%{$_.Trim(' ')}; RunAsTI $A[1] $A[2]; #:RunAsTI lean & mean snippet by AveYo, 2023.07.06
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Add-Type -AssemblyName System.Windows.Forms

$windir = [Environment]::GetFolderPath('Windows')
& "$windir\AtlasModules\initPowerShell.ps1"


$result = [System.Windows.Forms.MessageBox]::Show("There was an error when fixing Microsoft Store. Would you like to try again?", "Confirm", "YesNo", "Error")
if ($result -eq "Yes") {
[System.Windows.Forms.MessageBox]::Show("Please do not close the script under any circumstances. Doing so will result in your Windows installation to break significantly.", "Warning", "OK", "Warning") | Out-Null
& "$windir\AtlasDesktop\9. Troubleshooting\Fix MS Store Issues.cmd"
}
Binary file modified src/playbook/Executables/AtlasModules/Tools/StoreFixer.exe
Binary file not shown.
Loading