MSFN Forum: [Help] Deleting Profiles With Batch Files - MSFN Forum

Jump to content


Unattended CD/DVD Guide Homepage · MSFN Forum Rules

If you have questions about customizing Windows XP that are nLite-specific, please post them in the nLite forum, not here. If you have questions regarding the unattended installation of Windows XP, please post them in the Unattended Windows 2000/XP/2003 section.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Help] Deleting Profiles With Batch Files Rate Topic: -----

#1 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,036
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

  Posted 08 August 2006 - 01:46 PM

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. :)


#2 User is offline   Zxian 

  • Scroll up - see the Google bar?
  • Group: Super Moderator
  • Posts: 5,066
  • Joined: 30-September 04
  • OS:none specified
  • Country: Country Flag

Posted 08 August 2006 - 02:07 PM

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 User is offline   Sonic 

  • Sonic
  • Group: Patrons
  • Posts: 1,603
  • Joined: 04-December 03

Posted 08 August 2006 - 03:06 PM

@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 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,208
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 08 August 2006 - 03:08 PM

Why not just use the delprof.exe reskit utility?

http://www.microsoft.com/downloads/details...;displaylang=en

#5 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,036
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 08 August 2006 - 03:12 PM

View Postcluberti, on Aug 8 2006, 05:08 PM, said:

Why not just use the delprof.exe reskit utility?

http://www.microsoft.com/downloads/details...;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 User is offline   Sonic 

  • Sonic
  • Group: Patrons
  • Posts: 1,603
  • Joined: 04-December 03

Posted 08 August 2006 - 03:16 PM

View Postcluberti, on Aug 8 2006, 11:08 PM, said:

Why not just use the delprof.exe reskit utility?

http://www.microsoft.com/downloads/details...;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 ...

Quote

@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 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,036
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 08 August 2006 - 03:16 PM

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 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,364
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 08 August 2006 - 03:28 PM

View PostSonic, on Aug 8 2006, 10:06 PM, said:

<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 User is offline   Sonic 

  • Sonic
  • Group: Patrons
  • Posts: 1,603
  • Joined: 04-December 03

Posted 08 August 2006 - 03:35 PM

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 User is offline   gamehead200 

  • SEARCH!!! SEARCH!!!
  • Group: Super Moderator
  • Posts: 7,036
  • Joined: 02-September 02
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 08 August 2006 - 03:39 PM

View PostYzöwl, on Aug 8 2006, 05:28 PM, said:

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy