Solved

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

Posted on 2008-10-16
12
286 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:zerolincore
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:Angelized
Comment Utility
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

Next

Open in new window

0
 

Author Comment

by:zerolincore
Comment Utility
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.

Thanks..
0
 
LVL 3

Expert Comment

by:Angelized
Comment Utility
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)
 
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 250 total points
Comment Utility
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

0
 
LVL 18

Expert Comment

by:exx1976
Comment Utility
That batch file won't do it, it'll only empty that directory, not actually remove the profile..


Why not just use DelProf??

http://www.microsoft.com/downloads/details.aspx?familyid=901a9b95-6063-4462-8150-360394e98e1e&displaylang=en

delprof /I /D:0               should do it for you..
0
 
LVL 21

Expert Comment

by:AmazingTech
Comment Utility
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."
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 18

Expert Comment

by:exx1976
Comment Utility
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...
0
 
LVL 21

Expert Comment

by:AmazingTech
Comment Utility
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

0
 
LVL 18

Expert Comment

by:exx1976
Comment Utility
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.
0
 

Author Comment

by:zerolincore
Comment Utility
Sorry for late reply.

AmazingTech;
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.

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

Thanks for all.
0
 
LVL 21

Expert Comment

by:AmazingTech
Comment Utility
Really?

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

Author Closing Comment

by:zerolincore
Comment Utility
Thank you for your replies.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now