-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtakedown.cmd
38 lines (38 loc) · 1.69 KB
/
takedown.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@echo off & @rem based on XNT.kex script template version 2020-03-16
setlocal enableextensions & prompt @
if not "%~2" == "" call "%~0" "%*"
if not "%~2" == "" goto DONE & @rem expect one argument
if "%~1" == "" goto HELP & @rem expect one argument
if "%~1" == "?" goto HELP & @rem missing switch char
if "%~1" == "/?" goto HELP & @rem minimal requirement
if "%~1" == "-?" goto HELP & @rem permit DOS SWITCHAR
:DOIT --------------------------------------------------------------
set NEED=takeown.exe
for %%x in (%NEED%) do if not exist "%%~f$PATH:x" goto NEED
set NEED=%~f1
if not exist "%NEED%" goto NEED
if exist "%~1\*" set NEED=/R /A /F
if not exist "%~1\*" set NEED= /A /F
echo takeown.exe %NEED% "%~f1" 1>&2
@takeown.exe %NEED% "%~f1"
if errorlevel 1 echo Error: %0 got exit code [%ERRORLEVEL%]
if errorlevel 1 goto WAIT
if "%NEED%" == "/A /F" goto DONE
goto WAIT & @REM after recursive /R /A /F
:NEED --------------------------------------------------------------
echo/
echo Error: %0 found no "%NEED%"
:HELP --------------------------------------------------------------
echo Usage: %0 FILE
echo/
echo This admin shorthand for TAKEOWN.exe [/R] /A /F FILE uses /A /F
echo for a FILE or /R /A /F for a sub-directory tree. Option /A for
echo new owner admin-group, /R for recursive, see TAKEOWN.exe /?
echo/
echo Maybe create a shell::sendto shortcut (link) for
echo %%COMSPEC%% /k %~dpnx0
echo/
:WAIT if first CMD line option was /c ------------------------------
set NEED=usebackq tokens=2 delims=/
for /F "%NEED% " %%c in ('%CMDCMDLINE%') do if /I "%%c" == "c" pause
:DONE -------------- (Frank Ellermann, 2020) -----------------------