Solved

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

Posted on 2008-10-16
12
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:Angelized
ID: 22738982
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
ID: 22739734
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
ID: 22741240
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Accepted Solution

by:
AmazingTech earned 250 total points
ID: 22741988
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
ID: 22744632
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
ID: 22744835
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
 
LVL 18

Expert Comment

by:exx1976
ID: 22744879
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
ID: 22745216
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
ID: 22746886
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
ID: 22755734
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
ID: 22762014
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
ID: 31507056
Thank you for your replies.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 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