(view source code of delprof.bat as plain text)
@ECHO OFF
:: Check command line arguments and Windows version
IF "%1"=="" GOTO Syntax
IF NOT "%2"=="" GOTO Syntax
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
ECHO.%* | FIND "?" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
ECHO.%* | FIND "/" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
:: Use local environment copy
SETLOCAL
:: Check if TAKEOWN is available
SET TOXist=
FOR %%A IN (.;%Path%) DO IF EXIST "%%~A.\TAKEOWN.EXE" SET TOXist=1
IF NOT DEFINED TOXist GOTO Syntax
:: Workgroup or domain?
SET Domain=/DOMAIN
SET Profile=
FOR /F "tokens=2*" %%A IN ('NET CONFIG WORKSTATION 2^>NUL ^| FIND /I "Logon domain "') DO IF /I "%%B"=="%ComputerName%" SET Domain=
:: Check if command line argument is a valid user ID
NET USER "%~1" %Domain% >NUL 2>&1
IF ERRORLEVEL 1 GOTO Syntax
:: Recursively take ownership of profile directories and files
FOR /F "tokens=2*" %%A IN ('NET USER "%~1" %Domain% ^| FIND /I "User profile "') DO IF NOT "%%~B"=="" (
CALL :Own "%%~B"
)
:: Remove the profile directory
echo RD /S /Q "%Profile%"
:: Done
ENDLOCAL
GOTO:EOF
:Own
:: Display directory name
ECHO.%~1
:: Take ownership of specified directory
TAKEOWN "%~1"
:: Take ownership of files in specified directory
FOR /F "tokens=* delims=" %%A IN ('DIR /A-D /B "%~f1\*.*" 2^>NUL') DO TAKEOWN "%~1.\%%~A"
:: Recursively take ownership of subdirectories
FOR /F "tokens=* delims=" %%A IN ('DIR /AD /B "%~f1\*.*" 2^>NUL') DO CALL :Own "%~1.\%%~A"
GOTO:EOF
:Syntax
ECHO.
ECHO DelProf.bat, Version 0.50 Beta for Windows NT 4 / 2000 / XP
ECHO Delete the specified user profile
ECHO.
ECHO Usage: DELPROF userid
ECHO.
ECHO Where: userid is a valid user name
ECHO.
ECHO Note: This script requires TAKEOWN from the NT 4 Resource Kit
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:: Discard local environment copy if applicable
IF NOT "%1"=="" IF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0082 seconds