Create a batch file that deletes all user data folders except for All Users and Default User

batchscriptingwindows-xp

I am using Windows XP and would like to create a batch file that deletes all user data folders except for All Users and Default User. How can I achieve this?

Best Answer

First of all you don't want to delete the folders at OS level, instead you should be using delprof to accomplish this. Secondly, you can't delete the profile of a currently logged on user, so plan to run it as a computer startup script or run it remotely against a machine you know is switched on but doesn't have a user currently logged on.

So you need to have a look at this KB article which will provide you with all the info you need. The specific command you want will be something like:

delprof /q /i /c:computername