Solved

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

Posted on 2008-10-16
12
295 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
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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Running Access application from Task Scheduler 6 62
Excel 2016 loop through 6 43
Restart service script 5 14
Run AutoHotkey script directly from Notepad++ 5 73
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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