gamehead200 Posted August 8, 2006 Share Posted August 8, 2006 Hey everyone,Right now, I`m in the process of deleting profiles on 100+ laptops at my job in order to keep the computers clean. My question to you is the following... Is there a way to delete all the profiles EXCEPT certain ones by using a batch file? All this consists of is deleting the folders in the Documents and Settings folder and their contents except for certain folders (such as All Users and Administrator). There is a tool called delprof from Microsoft, but it just deletes everything except for the All Users folder. Can someone suggest a way of doing this?Thanks. Link to comment Share on other sites More sharing options...
Zxian Posted August 8, 2006 Share Posted August 8, 2006 You could use RoboCopy to move the unwanted files into the Recycle Bin, or to another temporary directorty that you then just delete. Robocopy has an option to exclude files/directories that match certain criteria.I'm sure that there are ways to make fancy "for all except" type statements in batchfiles, but I have no clue how to do them. Link to comment Share on other sites More sharing options...
Sonic Posted August 8, 2006 Share Posted August 8, 2006 @echo off&&clsecho Cleaning profiles ...for /f "tokens=*" %%a in ('dir "%AllUsersProfile%\.." /b') do (if not "%%a"=="Administrator" ( if not "%%a"=="All Users" rd /q /s "%AllUsersProfile%\..\%%a" 2>NUL ))echo Done.echo.echo New profiles list :dir "%AllUsersProfile%\.." /bpause>NULThat clears all profiles except All Users and Admin.It re-display list of profile to check if all it's done (for example to check if a file/folder is persistent ...)Please Yzöwl do not ridicule (?) me with your future compacted/optimized batch ^^ Link to comment Share on other sites More sharing options...
cluberti Posted August 8, 2006 Share Posted August 8, 2006 Why not just use the delprof.exe reskit utility?http://www.microsoft.com/downloads/details...;displaylang=en Link to comment Share on other sites More sharing options...
gamehead200 Posted August 8, 2006 Author Share Posted August 8, 2006 Why not just use the delprof.exe reskit utility?http://www.microsoft.com/downloads/details...;displaylang=enAs I mentioned above... It doesn't do what I want. Delprof either deletes all the profiles except for Administrator and All Users or prompts you for each profile. There are 300+ profiles on most of the desktops I will be using this on!!! Also, I will be doing this from an account that has Admin privileges, so I don't want the Administrator folder to be deleted. Sonic, how would I add two profiles I do not want to delete to that batch file? For example, the names of the folders are "profile1" and "profile2". Link to comment Share on other sites More sharing options...
Sonic Posted August 8, 2006 Share Posted August 8, 2006 Why not just use the delprof.exe reskit utility?http://www.microsoft.com/downloads/details...;displaylang=enBecause it deletes Administrator account too, isn't gamehead200 says ? (I havn't check myself ...)edit: gamehead200 was fatest than my quote. ^^Just add an "if" statement ...@echo off&&clsecho Cleaning profiles ...for /f "tokens=*" %%a in ('dir "%AllUsersProfile%\.." /b') do (if not "%%a"=="AnotherAccountYouWantToKeep" ( if not "%%a"=="Administrator" ( if not "%%a"=="All Users" rd /q /s "%AllUsersProfile%\..\%%a" 2>NUL ))echo Done.echo.echo New profiles list :dir "%AllUsersProfile%\.." /bpause>NUL Link to comment Share on other sites More sharing options...
gamehead200 Posted August 8, 2006 Author Share Posted August 8, 2006 Thanks a lot! I'll give it a try tomorrow! Oh, and I almost forgot... The Default User folder... I just add that in as mentioned above? Link to comment Share on other sites More sharing options...
Yzöwl Posted August 8, 2006 Share Posted August 8, 2006 <snip>That clears all profiles except All Users and Admin.It re-display list of profile to check if all it's done (for example to check if a file/folder is persistent ...)Please Yzöwl do not ridicule (?) me with your future compacted/optimized batch ^^Now would I do that!@ECHO OFF &SETLOCALFOR /D %%? IN ("%ALLUSERSPROFILE:\ALL USERS=%\*") DO ( ECHO/%%~N? |FINDSTR/IL "ADMINISTRATOR ALL\ USERS" >NUL 2>&1||RD/S/Q "%%~?") Link to comment Share on other sites More sharing options...
Sonic Posted August 8, 2006 Share Posted August 8, 2006 Yzöwl ? the best ? ... YES!For gamehead200, replace "ADMINISTRATOR ALL\ USERS" by all your wanted profiles, if space is in profile insert \ as same in example with All Users ... Link to comment Share on other sites More sharing options...
gamehead200 Posted August 8, 2006 Author Share Posted August 8, 2006 Now would I do that!@ECHO OFF &SETLOCALFOR /D %%? IN ("%ALLUSERSPROFILE:\ALL USERS=%\*") DO ( ECHO/%%~N? |FINDSTR/IL "ADMINISTRATOR ALL\ USERS" >NUL 2>&1||RD/S/Q "%%~?")Holy crap, that's freakin' short and amazing!! Thanks guys!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now