Script or Batch file - Delete all folders EXCEPT ... also Remote Management help

I need a script or a batch file that can either be run automatically or manually by us, remotely.  It should do the following to each of 17 computers in a lab.  The computers are running XP Pro SP-2.

1) Restart all of the computers (I know how to do this, and figure I would need two scripts, one to run after the other... how do I set that up?)
2) Inside of a C:\Documents and Settings - Delete all folders except for:
     - All Users
     - Administrator
     - Default User
     - Any other system folders that need to stay in there.

We do not know what the names of the folder would be... otherwise this would be a very simple batch.  Not only can the folders in there be any one of 800 or so users, it may also be variations of that user's login name (such as doejohn.000, doejohn.001, etc.).

I would also need some way of knowing that the folders were successfully deleted.  A single log would be nice, back at my (the remote administrator) computer.  One log file per machine would be not so nice (but workable), and I would need some way of collecting and analyzing all 17 files quickly.

Unfortunately, folder sharing is not a solution for us here.  If this task simply cannot be done, please explain that and why, if you could.

We eventually plan on expanding this to all of the PC's that we manage (200+), and are using this lab simply as a pilot.  Getting this to be as automated as possible is very important.  Actually scheduling the task to run automatically will not be a problem, as I already know how to do this.  It would be best to use the remote management capabilities of XP (see below) but I can also work with putting a script or batch file on each workstation, if need be.

This script would serve as a temporary fix for another issue we are having, detailed here: http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21210077.html.  That issue is still unsolved, is directly related to the Autodesk licensing service, and is worth 500 points.

On a side note... if you can give any suggestions, links, tutorials, etc. on managing remote XP Pro machines, please do so.  We currently use UltraVNC and Remote Desktop on occasion, but I know there is a way to connect to computer management, and I'm sure plenty of other things, using another remote XP Pro machine.  I'm looking for a detailed list or something that goes through all the possibilites, command line or not.  For instance - stopping and starting a service on 100 computers at once, and (hopefully) getting conformation of any failures.

Points will be split if you can answer a piece of the question.

Thanks in advance,
~ Jonny
LVL 4
jonnyz0109Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tymesCommented:
I told mentioned the  HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DeleteRoamingCache REG_DWORD and DELPROF.EXE in the other thread, but you can also put this a logon script...


REM for each roaming user directory delete the local
set userprofilesdir="C:\Documents and Settings"
pushd %userprofiledir%
for %%d in ("\\server\userprofiles$\*") do (
 if "%%~nd" neq "%username%" rd /s /q "%userprofiledir%\%%~nd"
)
popd

or

REM for each local directory that isn't current or special delete it
set userprofilesdir="C:\Documents and Settings"
pushd %userprofiledir%
for %%d in (*) do (
 if "%%~fd" neq "%userprofile%" if "%%d" neq "All Users" if "%%d" neq "Default User" if "%%d" neq "LocalSystem" if "%%d" neq "NetworkService" rd /s /q %%d
)
popd

Or I might put a special ".donotdelete" file in each special directory and do a for IF NOT EXIST %D\.donotdelete then delete.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jonnyz0109Author Commented:
Can you please show me how to do the second script using the "donotdelete" file?  
0
tymesCommented:
Oh, I forgot /D between each of the FOR %%d above to iterate through directories instead of files... oops.  Use "FOR /d %%d" in each of my examples above.
so anyways, something like ...

for /d %%d in ("C:\Documents and Settings\*") do if NOT EXIST "%%d\_DO_NOT_DELETE_PROFILE"  echo rd /q /s "%%d"

Create files called _DO_NOT_DELETE_PROFILE in each of the directories that you don't want it to delete (if it doesn't find the file then it will try to delete the directory), this may actually pose a problem if it doesn't have permission to look at that file in which case it will try to delete the directory.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

jonnyz0109Author Commented:
Tymes, that sounds good!  Unfortunately I will not be back to the PC labs until Next monday, which is when I can test this out some more.  It'd be great if you can check back and I will let you know how things go.

Thanks for your help in both of these questions!

~ Jonny
0
jonnyz0109Author Commented:
Thank you very much for your help... I am using the second script above without the do not delete file.  We plan on running this batch script on every PC on startup (before anyone logs in) to get rid of all profiles.  I think this should solve our problem!

Thanks again,

Jonny
0
adamshieldsCommented:
I tried placing the following into a bat file but it didn't run? Any suggestions? Thanks

set userprofilesdir="C:\Documents and Settings"
pushd %userprofiledir%
for %%d in (*) do (
 if "%%d" neq "Administrator" if "%%d" neq "All Users" if "%%d" neq "Default User" if "%%d" neq "LocalSystem" if "%%d" neq "NetworkService" rd /s /q %%d
)
popd
0
jonnyz0109Author Commented:
He posted a second time with a modification to his original code... you're missing the /d flag.  Here is my code for the working script:

echo off
echo. >> "C:\Profile Cleanup\Profile Cleanup.log"
echo -------------------- %time%: SYSTEM STARTUP - PROFILE CLEANUP -------------------- >> "C:\Profile Cleanup\Profile Cleanup.log"
echo Script running as %username%. >> "C:\Profile Cleanup\Profile Cleanup.log"
pushd "C:\Documents and Settings"
for /d %%d in (*) do ( if "%%~fd" neq "%userprofile%" if "%%d" neq "All Users" if "%%d" neq "Default User" if "%%d" neq "LocalService" if "%%d" neq "NetworkService" if "%%d" neq "user" if "%%d" neq "Administrator" rd /s /q "%%d" & echo Deleting directory "%%d" >> "C:\Profile Cleanup\Profile Cleanup.log" )
popd
echo -------------------- %time%: PROFILE CLEANUP COMPLETE -------------------- >> "C:\Profile Cleanup\Profile Cleanup.log"
echo. >> "C:\Profile Cleanup\Profile Cleanup.log"
0
jonnyz0109Author Commented:
the echo's are optional.  I have the script writing to a log file so I can go into each individual machine and see that the script has been working properly, what it's been deleting, etc.
0
adamshieldsCommented:
That worked well but when I added the script to logoff in gpedit.msc, it only works when the administrator logs off and not reguler users logoff?
0
jonnyz0109Author Commented:
My first thought: It probably needs administrator access to run.  Try setting permissions to everyone?  On second thought: technically when the logoff script executes, you're still logged in, right?  You can't delete a user's directory that is still logged in... This script really needs to be run either a) when one of the "exempt" users is logged in (i.e. "user" for me or "administrator" otherwise), or when nobody is logged in.  For that reason:

What I did was create a process using srvany.exe and I even created a little installer so the techs can easily install the script onto a new XP image (I left the job for now to go back to school).  The process runs at system startup before anybody even logs off.  If this isn't enough to get you started you might want to open a new question... that way you will get multiple experts participating.  Just post a link here if you want tymes and/or me to participate   :o)
0
adamshieldsCommented:
0
jonnyz0109Author Commented:
I'll watch that thread.  Thanks

~ Jonny  :o)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.