Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

[Help] Deleting Profiles With Batch Files

- - - - -

  • Please log in to reply
9 replies to this topic

#1
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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. :)


How to remove advertisement from MSFN

#2
Zxian

Zxian

    Scroll up - see the Google bar?

  • Super Moderator
  • 5,066 posts
  • OS:none specified
  • Country: Country Flag
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. :P

#3
Sonic

Sonic

    Sonic

  • Patrons
  • 1,603 posts
@echo off&&cls
echo 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%\.." /b
pause>NUL

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 ^^

#4
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,252 posts
  • OS:Windows 8.1 x64
  • Country: Country Flag
Why not just use the delprof.exe reskit utility?

http://www.microsoft...;displaylang=en
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!

#5
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Why not just use the delprof.exe reskit utility?

http://www.microsoft...;displaylang=en


As 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!!! :wacko: 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". :}

#6
Sonic

Sonic

    Sonic

  • Patrons
  • 1,603 posts

Why not just use the delprof.exe reskit utility?

http://www.microsoft...;displaylang=en


Because 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&&cls
echo 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%\.." /b
pause>NUL



#7
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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?

#8
Yzöwl

Yzöwl

    Wise Owl

  • Member
  • PipPipPipPipPipPipPipPipPip
  • 4,532 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

<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 &SETLOCAL
FOR /D %%? IN ("%ALLUSERSPROFILE:\ALL USERS=%\*") DO (
  ECHO/%%~N? |FINDSTR/IL "ADMINISTRATOR ALL\ USERS" >NUL 2>&1||RD/S/Q "%%~?")


#9
Sonic

Sonic

    Sonic

  • Patrons
  • 1,603 posts
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 ...

#10
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Now would I do that!

@ECHO OFF &SETLOCAL
FOR /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!! :w00t:

Thanks guys!! :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN