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?
AmazingTechConnect With a Mentor Commented:
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

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.

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

All Courses

From novice to tech pro — start learning today.