[cmd scripts] Elavate Using PS & VBS (With Args)

Discussion in 'Scripting' started by Dark Dinosaur, Jul 22, 2021.

  1. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,734
    5,179
    120
    #1 Dark Dinosaur, Jul 22, 2021
    Last edited: Sep 23, 2021
    Elavate Using PS & VBS (With Args)

    Sometimes it not show 'Administrator' in title
    but it run with elevate rights !


    Code:
    @cls
    @echo off
    setlocal enabledelayedexpansion
    title Put program title here
    
    rem https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
    rem https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
    
    :: V1
    
    REM cd /d "%~dp0"
    REM 1>nul 2>nul fltmc || (1>nul 2>nul pushd "%windir%\System32\WindowsPowershell\v1.0\" && (
        REM (set args=%*)&(if /i '!args!' NEQ '' set args=-ArgumentList ""!args!"")
        REM powershell "Start-Process -Verb RunAs -FilePath """%~dpf0""" !args!") || (
        REM >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpf0", "%*" , "", "runas", 1
        REM "%temp%\Elevate.vbs"&del /q "%temp%\Elevate.vbs">nul)
    REM exit)
    
    :: V2
    
    cd /d "%~dp0"
    1>nul 2>nul fltmc || (1>nul 2>nul pushd "%windir%\System32\WindowsPowershell\v1.0\" && (
        (set args=%*)&(if /i '!args!' NEQ '' set args=-arg '!args!')
        powershell "Start """%~dpf0""" -Verb RunAs !args!") || (
        >"%temp%\Elevate.vbs" echo CreateObject^("Shell.Application"^).ShellExecute "%~dpf0", "%*" , "", "runas", 1
        "%temp%\Elevate.vbs"&del /q "%temp%\Elevate.vbs">nul)
    exit)
    
    :: put your script here
    echo.&echo Success gain admin privileges
    echo args :: ^<%*^>
    pause
    
    echo.&echo.
    echo fltmc Command&echo.&echo.
    fltmc
    echo net session Command&echo.&echo.
    net session
    echo NET FILE Command&echo.&echo.
    NET FILE
    echo reg query Command&echo.&echo.
    reg query "HKU\S-1-5-19"
    echo fsutil dirty query Command&echo.&echo.
    fsutil dirty query C:
    timeout 10
    goto :eof
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...