Request _ Need a script or a batch file which deletes the user profiles.

Hello Experts.

We have got a terminal server which thin clients (more than 200) log on to it.
When the thin clients log on they use their profiles. For example number1 uses internet1 profile. Number2 uses internet2 profile. It goes on like this.

Now I need a script or a batch file when i run this batch file all the profile folders (ex. internet1, internet2....etc) under the Documents and Settings Folder must be deleted.

Could you please help me about this batch file or script?

Thanks For all.
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.

Something like this ?
Const USER_PROFILE = &H28&
Set objShell = CreateObject("Shell.Application")
Dim fso
Set fso = CreateObject("scripting.filesystemobject")
Set objFolder = objShell.Namespace(USER_PROFILE)
Set objFolderItem = objFolder.ParentFolder
Set colItems = objFolderItem.Items
For Each objItem in colItems
   fso.DeleteFolder objItem.Path

Open in new window

zerolincoreAuthor Commented:
Thank Angelized for your reply.

But I am not good at scripting.

What does this script do?

Can you explain some? And is it a VBS file.

Yes, it's a VBS
Basically, It list all the profiles on the current computer and delete them. Don't run it on your computer. ;) basically the script will fail to delete the profiles in uses (file lock)
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Here's what you asked for it's a .bat file. It will only delete profiles which starts with Internet.

Warning Angelized script will delete all profiles this includes Administrator if you're not logged on as Administrator.
FOR /f "Tokens=*" %%a in ('dir /b /ad "C:\Documents and Settings\Internet*"') do RD /q /s "C:\Documents and Settings\%%a"

Open in new window


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
That batch file won't do it, it'll only empty that directory, not actually remove the profile..

Why not just use DelProf??

delprof /I /D:0               should do it for you..
Once the directory is gone what is left over? Everything is in that directory unless folder redirection was enabled.

"Now I need a script or a batch file when i run this batch file all the profile folders (ex. internet1, internet2....etc) under the Documents and Settings Folder must be deleted."
I don't know about on 2003 (I have scheduled DelProf on my Citrix boxes since they were built), but in my old 2000 TS environment, it used to still list the users profiles on the profiles tab of My Computer properties...
Leftovers in the registry.

HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList

Here's a script to take care of that too.
FOR /f "Tokens=*" %%a in ('dir /b /ad "C:\Documents and Settings\Internet*"') do (
    RD /q /s "C:\Documents and Settings\%%a"
    IF NOT EXIST "C:\Documents and Settings\%%a" (
        FOR /f "Tokens=*" %%b in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" ^| FIND /I "S-1-5-21-"') DO (
            REG QUERY "%%b" /v ProfileImagePath | FIND /I "\%%a"
            IF NOT ERRORLEVEL 1 REG DELETE "%%b" /f

Open in new window

That's all well and good, I use a ton of VBscript here (batch is kinda dated, though still viable), and have posted at least a dozen in the past two days..  I just believe in the right tool for the right job...  Just put DelProf in the task scheduler to run every night and remove everything older than, say, 30 days, and you never have this problem again.
zerolincoreAuthor Commented:
Sorry for late reply.

thank you for your relplies. Your first code deleted internet* profile folders contents. But the profile folder was not deleted.  Your second script done nothing. May be there is a problem somewhere. I am not good at scripting. So I could not find the problem. Can you please reconfigure this script for my request.

delprof is a good utility but is not what I want. Thanks.

Thanks for all.

Can you post what this output provides?

FOR /f "Tokens=*" %%a in ('dir /b /ad "C:\Documents and Settings\Internet*"') do Echo "C:\Documents and Settings\%%a"

From a command line:

FOR /f "Tokens=*" %a in ('dir /b /ad "C:\Documents and Settings\Internet*"') do Echo "C:\Documents and Settings\%a"

If the users are logged on or your having problems with the registry not unloading when the users logoff or the Citrix Session is still active then the one file it won't be able to remove is ntuser.dat which is hidden.
zerolincoreAuthor Commented:
Thank you for your replies.
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
VB Script

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.