Lean And Mean snippets for power users RunAsTI / reg_own / ToggleDefender / Edge removal / redirect

Discussion in 'Scripting' started by AveYo, May 7, 2021.

  1. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,828
    7,144
    150
    #201 Dark Vador, Aug 4, 2025
    Last edited: Aug 4, 2025
    So, after little upgrde -> just make sure, to be with administrator prev.
    Changes ? now windows visible, with new flags
    And, 1 call only, instead 4 (User -> Elavate Admin -> Elavate System -> Run Command Under System
    and i can do even better, make it encoded :D
    im impress from this code, he skip few APi, and write manualy structs'

    * any one notice, that, he just grab handle, from current running process,
    * which, i thought, it should nt be work, but it does work.!
    Code:
    function RunAsTI {
        param (
            $CommndLine
        )
        $I=[int32];
        $M=$I.module.gettype("System.Runtime.InteropServices.Marshal");
        $P=$I.module.gettype("System.IntPtr");
        $S=[string]; $D=@(); $T=@(); $Z=[uintptr]::size
        $DM=[AppDomain]::CurrentDomain."DefineDynamicAssembly"(1,1)."DefineDynamicModule"(1);
        0..5|% {$D += $DM."DefineType"("AveYo_$_",1179913,[ValueType])};
        $D += [uintptr];
        4..6|% {$D += $D[$_]."MakeByRefType"()}
        $F='kernel','advapi','advapi', ($S,$S,$I,$I,$I,$I,$I,$S,$D[7],$D[8]), ([uintptr],$S,$I,$I,$D[9]),([uintptr],$S,$I,$I,[byte[]],$I)
        0..2|% {$9=$D[0]."DefinePInvokeMethod"(('CreateProcess','RegOpenKeyEx','RegSetValueEx')[$_],$F[$_]+'32',8214,1,$S,$F[$_+3],1,4)}
        $DF=($P,$I,$P),($I,$I,$I,$I,$P,$D[1]),($I,$S,$S,$S,$I,$I,$I,$I,$I,$I,$I,$I,[int16],[int16],$P,$P,$P,$P),($D[3],$P),($P,$P,$I,$I)
        1..5|% {$k=$_; $n=1; $DF[$_-1]|% {$9=$D[$k]."DefineField"('f' + $n++, $_, 6)}};
        0..5|% {$T += $D[$_]."CreateType"()}
        0..5|% {nv "A$_" ([Activator]::CreateInstance($T[$_])) -fo};
        function F ($1,$2) {$T[0]."GetMethod"($1).invoke(0,$2)}
        $TI=(whoami /groups)-like'*1-16-16384*'; $As=0;
        'TrustedInstaller','lsass','winlogon'|% {if (!$As) {$9=sc.exe start $_; $As=@(get-process -name $_ -ea 0|% {$_})[0]}}
        function M ($1,$2,$3) {$M."GetMethod"($1,[type[]]$2).invoke(0,$3)};
        $H=@(); $Z,(4*$Z+16)|% {$H += M "AllocHGlobal" $I $_}
        M "WriteIntPtr" ($P,$P) ($H[0],$As.Handle);
        # PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000
        $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 "StructureToPtr" ($D[2],$P,[boolean]) (($A2 -as $D[2]),$A4.f2,$false)
        $Run=@($null, $CommndLine, 0, 0, 0, (0x00080000 -bor 0x00000010) , 0, $null, ($A4 -as $T[4]), ($A5 -as $T[5]))
        F 'CreateProcess' $Run;
    }
    RunAsTI -CommndLine "cmd /k whoami"
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. JeepWillys58

    JeepWillys58 MDL Addicted

    Nov 6, 2010
    608
    386
    30
    Hi Dear friend,

    Did you know if it's still working on new 23H2 eg 22631.6345?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. verndog

    verndog MDL Senior Member

    May 3, 2010
    277
    124
    10
    I think 'Dark Vador" is banned, so he won't be able to comment. Someone reported that he now has his own site. Unsure where I saw the post.
     
  4. iaTa

    iaTa MDL Junior Member

    Jul 30, 2009
    96
    31
    0
    #204 iaTa, Jul 22, 2026
    Last edited: Jul 25, 2026
    Toggle Defender no longer works on Windows 11 26200.8968.

    I've tried the bat and ps1 as a normal user and as an admin.

    Script runs with no output and no longer disables Defender.
     
  5. BetaTesta

    BetaTesta MDL Senior Member

    Aug 6, 2022
    326
    111
    10
  6. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    55,205
    126,990
    450
    #206 Enthousiast, Jul 28, 2026
    Last edited: Jul 28, 2026
    It worked fine a few minutes ago on 26300.

    Disable "Tamper Protection" first and run the cmd:

    [​IMG]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Tiger-1

    Tiger-1 MDL Guru

    Oct 18, 2014
    8,366
    11,720
    270
    you are the dude always :p
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    55,205
    126,990
    450
    I just happened to be testing UUP>ISO conversions and wanted to know if defender was causing something, and i always use toggle defender by BAU / AveYo when i can.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. iaTa

    iaTa MDL Junior Member

    Jul 30, 2009
    96
    31
    0
    Yeah tamper protection is disabled but I still can't get it to work.

    Been using it for years also.