2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ファイルを投げ込むとプロンプトが出て管理者として実行できるバッチファイルを作るバッチファイル、4種 !?

Last updated at Posted at 2023-03-23
create.autouac.vb.cmd
@echo off
setlocal enableextensions disabledelayedexpansion
set chk_args=%1
if not defined chk_args goto :end
for %%A in (%*) do (
    echo %%~xA |findstr /I /V ".bat .cmd" >nul 2>&1
    if errorlevel 1 (
        (
            echo @echo off
            echo :chk_admin
            echo openfiles ^>nul 2^>^&1
            echo if errorlevel 2 goto :got_admin
            echo if not errorlevel 1 goto :got_admin
            echo :get_admin
            echo echo.
            echo echo ***********************************
            echo echo Invoking UAC to escalate privilege
            echo echo ***********************************
            echo setlocal enableextensions disabledelayedexpansion
            echo set tempfile="%%temp%%\~RUNAS%%random%%.vbs"
            echo set args="%%~f0" %%*
            echo.
            echo ::echo WScript.CreateObject("Shell.Application"^^^).ShellExecute "cmd.exe","/c """ ^^^& "%%args:"=""%%^""","","RunAs",1 ^>%%tempfile%%
            echo ::wscript.exe %%tempfile%%
            echo.
            echo echo WScript.CreateObject("Shell.Application"^^^).ShellExecute "cmd.exe","/c """ ^^^& Replace(WScript.Arguments(0^^^),"/",""""^^^) ^^^& """","","RunAs",1 ^>%%tempfile%%
            echo wscript.exe %%tempfile%% "%%args:"="/"%%^"
            echo.
            echo :ZrnTjdIP
            echo if exist %%tempfile%% del /F /A %%tempfile%%
            echo if exist %%tempfile%% goto :ZrnTjdIP
            echo endlocal
            echo exit
            echo :got_admin
        ) >"%%~dpnA.autouac.vb%%~xA"
        type %%A >>"%%~dpnA.autouac.vb%%~xA"
        echo.
        echo "%%~nA.autouac.vb%%~xA" Done.
    ) else (
        echo.
        echo "%%~nxA" This file is not a batch file and cannot be processed.
        echo.
        pause
    )
)
exit
:end
echo.
echo Give me the source batch file(s^) as argument(s^).
echo.
pause
exit

create.autouac.js.cmd
@echo off
setlocal enableextensions disabledelayedexpansion
set chk_args=%1
if not defined chk_args goto :end
for %%A in (%*) do (
    echo %%~xA |findstr /I /V ".bat .cmd" >nul 2>&1
    if errorlevel 1 (
        (
            echo @echo off
            echo :chk_admin
            echo openfiles ^>nul 2^>^&1
            echo if errorlevel 2 goto :got_admin
            echo if not errorlevel 1 goto :got_admin
            echo :get_admin
            echo echo.
            echo echo ***********************************
            echo echo Invoking UAC to escalate privilege
            echo echo ***********************************
            echo setlocal enableextensions disabledelayedexpansion
            echo set tempfile="%%temp%%\~RUNAS%%random%%.js"
            echo set args="%%~f0" %%*
            echo.
            echo ::set args=%%args:\=\\%%
            echo ::echo WScript.CreateObject("Shell.Application"^^^).ShellExecute("cmd.exe",'/c ^^^"' + '%%args:'=\'%%^^^"',"","RunAs",1^^^); ^>%%tempfile%%
            echo ::wscript.exe %%tempfile%%
            echo.
            echo echo WScript.CreateObject("Shell.Application"^^^).ShellExecute("cmd.exe",'/c ^^^"' + WScript.Arguments(0^^^).replace(/[/]/g,'^^^"'^^^) + '^^^"',"","RunAs",1^^^) ^>%%tempfile%%
            echo wscript.exe %%tempfile%% "%%args:"="/"%%^"
            echo.
            echo :ZrnTjdIP
            echo if exist %%tempfile%% del /F /A %%tempfile%%
            echo if exist %%tempfile%% goto :ZrnTjdIP
            echo endlocal
            echo exit
            echo :got_admin
        ) >"%%~dpnA.autouac.js%%~xA"
        type %%A >>"%%~dpnA.autouac.js%%~xA"
        echo.
        echo "%%~nA.autouac.js%%~xA" Done.
    ) else (
        echo.
        echo "%%~nxA" This file is not a batch file and cannot be processed.
        echo.
        pause
    )
)
exit
:end
echo.
echo Give me the source batch file(s^) as argument(s^).
echo.
pause
exit

create.autouac.hybrid.cmd
@echo off
setlocal enableextensions disabledelayedexpansion
set chk_args=%1
if not defined chk_args goto :end
for %%A in (%*) do (
    echo %%~xA |findstr /I /V ".bat .cmd" >nul 2>&1
    if errorlevel 1 (
        (
            echo @if(0^)==(0^) echo off
            echo :chk_admin
            echo openfiles ^>nul 2^>^&1
            echo if errorlevel 2 goto :got_admin
            echo if not errorlevel 1 goto :got_admin
            echo :get_admin
            echo echo.
            echo echo ***********************************
            echo echo Invoking UAC to escalate privilege
            echo echo ***********************************
            echo setlocal enableextensions disabledelayedexpansion
            echo set args="%%~f0" %%*
            echo CScript.exe "%%~f0" //E:JScript //Nologo "%%args:"="/"%%^"
            echo endlocal
            echo exit
            echo @end
            echo var shl=WScript.CreateObject("WScript.Shell"^)
            echo var openfiles=shl.ExpandEnvironmentStrings("%%ComSpec%%\\..\\openfiles.exe"^)
            echo if (WScript.CreateObject("Scripting.FileSystemObject"^).FileExists(openfiles^)^) {
            echo     if (! shl.Run("openfiles.exe",0,"True"^)==0^) {
            echo         WScript.CreateObject("Shell.Application"^).ShellExecute("cmd.exe",'/c ^"' + WScript.Arguments(0^).replace(/[/]/g,'^"'^) + '^"',"","RunAs",1^)
            echo     }
            echo }
            echo openfiles=null
            echo shl=null
            echo @if(0^)==(0^) echo off
            echo :got_admin
        ) >"%%~dpnA.autouac.hybrid%%~xA"
        type %%A >>"%%~dpnA.autouac.hybrid%%~xA"
        (
            echo @end
        ) >>"%%~dpnA.autouac.hybrid%%~xA"
        echo.
        echo "%%~nA.autouac.hybrid%%~xA" Done.
    ) else (
        echo.
        echo "%%~nxA" This file is not a batch file and cannot be processed.
        echo.
        pause
    )
)
exit
:end
echo.
echo Give me the source batch file(s^) as argument(s^).
echo.
pause
exit

create.autouac.ps.cmd
@echo off
setlocal enableextensions disabledelayedexpansion
set chk_args=%1
if not defined chk_args goto :end
for %%A in (%*) do (
    echo %%~xA |findstr /I /V ".bat .cmd" >nul 2>&1
    if errorlevel 1 (
        (
            echo @echo off
            echo.
            echo :chk_admin
            echo openfiles ^>nul 2^>^&1
            echo if errorlevel 2 goto :got_admin
            echo if not errorlevel 1 goto :got_admin
            echo.
            echo :get_admin
            echo echo.
            echo echo ***********************************
            echo echo Invoking UAC to escalate privilege
            echo echo ***********************************
            echo.
            echo setlocal enableextensions disabledelayedexpansion
            echo set args="%%~f0" %%*
            echo set args=^^^"%%args:'=''%%^^^"
            echo powershell.exe -Command "Start-Process -FilePath ${env:comspec} -ArgumentList '/c %%args:"="""%%' -Verb RunAs"
            echo endlocal
            echo exit
            echo.
            echo :got_admin
        ) >"%%~dpnA.autouac.ps%%~xA"
        type %%A >>"%%~dpnA.autouac.ps%%~xA"
        echo.
        echo "%%~nA.autouac.ps%%~xA" Done.
    ) else (
        echo.
        echo "%%~nxA" This file is not a batch file and cannot be processed.
        echo.
        pause
    )
)
exit
:end
echo.
echo Give me the source batch file(s^) as argument(s^).
echo.
pause
exit

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?