Link to home
Start Free TrialLog in
Avatar of TPS1979
TPS1979

asked on

Windows DOS Batch Profile Removal

Hi there
I have found the following code on here which enables me to delete profiles very well. However i have hundreds of machines with duplicate profiles on and if i run this code it deletes the current users profile.
This is because everytime someone logs in to the machine an additional profile gets created and the code does not read this as a current user profile and attempts to delete it.
For example, Person A has a profile on the machine, they restart the machine and log in again, Person A then has a profile called Person A.WorkstationName. The code looks for the current user can't find it and deletes the profile Person A.WorkstationName which is currently being used.
If anyone could offer any advice it would be appreciated.
@echo off
for /f "tokens=*" %%a in ('dir c:\docume~1 /b /ad') do call :process "%%a"
goto :eof

:process
if [%1]==["Administrator"] goto :eof
if [%1]==["All Users"] goto :eof
if [%1]==["Default User"] goto :eof
if [%1]==["LocalService"] goto :eof
if [%1]==["NetworkService"] goto :eof
if [%1]==["Mits"] goto :eof
if [%1]==["Student"] goto :eof
if [%1]==["NWUSERNAME"] goto :eof
if [%1]==["USERNAME"] goto :eof
cd\docume~1
echo. About to remove profile %1
pause
rmdir %1 /s /q

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TPS1979
TPS1979

ASKER

Very impressed, worked a treat! Thank you.
No problem.... you just have to know some tricks sometimes.  Lots of info in the help texts of hte commands such as set /? for /? etc. and frankly learned most of the new stuff here over the years!

Of course if some users sets something like their profile path to c:\myname then the above could cause a few issues shall we say.... as in the root profiles dir would then be seen as c:\ ....

Good luck with anyway and just stick a question on here if it causes any issues

Steve