Solved

Windows XP Local Locked User Profiles - AUTOMATED DELETION ?

Posted on 2006-10-31
8
741 Views
Last Modified: 2012-05-05
Hello everyone,


I work in a school district where there are multiple users on each workstation everyday. We have Windows XP SP2 boxes with Novell Netware 6.5 and Zen 7. The applications are all pushed out through Novell Application Launcher.

The issue is almost everyday we are getting calls for strange things occuring on the workstations such as not being able to save word files and other oddities. What we have been able to track this down to is that user profiles are getting stuck locally on the machine. Their should only be the profiles "Default User" "Admin" and "Administrator" on these machines. Instead we are seeing students logins and teachers logins that have gotten stuck on the local machine.

What I need is a way to automatically delete all the profiles except for the ones mentioned above I also need to perform several other procedures such as

Clearing out the temp and temporary internet files each night
Clearing out Microsoft Office Temp Files
I know how to do the later part in a batch file but I am not sure how I can make it so that I can delete all profiles except certain ones. I am looking for either a standard batch file way or a windows scripting way (although I am not all that familiar with windows scriptiing)
0
Comment
Question by:briancassin
  • 3
  • 2
8 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17845963
On Error Resume Next

Dim obtainfolder, PathFolder, strPath, x, strFolder()

 Set fso = CreateObject("Scripting.FileSystemObject")

 strPath = "C:\Documents and Settings\"

 Set f = fso.GetFolder(strPath)

 x=0

 For Each fldrItem in f.SubFolders

  fldrName = fldrItem.name

  If Right(strPath,1) <> "\" Then

   PathFolder = strPath & "\" & fldrName

  Else

   PathFolder = strPath & fldrName

  End If

  Select Case fldrName

   Case "Administrator", "All Users", "Default User", "LocalService", "NetworkService":

   Case "supervisor.CSE2K"

   Case "supervisor"

   Case "sweepupd"

   Case "sweepupd.CSE2K"

   Case Else:

            ReDim Preserve strFolder(x)

            strFolder(x) = PathFolder

            x=x+1

    set obtainfolder = fso.GetFolder(PathFolder)    

    obtainfolder.Delete true      

 End Select

 Next

 

for x = 0 to ubound(strFolder)

  strMsg=strMsg & vbCrLf & strFolder(x)

next

 

msgbox "Profiles Deleted:" & vbCrLf & strMsg

 

 ' Clean up objects

 Set fso = Nothing

 Set fc = Nothing

'------

That is in vbscript so if you copy and paste the above into notepad and when you go to save as just put double quotes around a name with a .vbs extension ie

"Script.vbs"

That way it changes the file type to a vbscript.

There are a few more case selects which you may not need ie

   Case "sweepupd"

   Case "sweepupd.CSE2K"

Which you can just delete from the script, but if it does not find them then I dont think it will make any difference anyway.

I mainly put that in there because we use sophos which creates those folders afaik ( correct me if I am wrong ).

Anyway That should get you pointed in the right direction.

As for checking for back slashes at the start of the script, I was just trying to make sure that the path was correct ie

I didn't want it to be something like so :

c:\documents and settingsusername

Otherwise the script would crash as it would not know what to delete and I wanted to make sure that there was always a slash separating the username and the documents and settings ( If that makes sense )
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 17846014
User Profile Hive Cleanup Service
http://www.microsoft.com/downloads/details.aspx?FamilyID=1B286E6D-8912-4E18-B570-42470E2F3582&displaylang=en

That might be able to help unload the profiles.

As for the Deletion via a batch file, gimme a few minutes...

0
 
LVL 66

Expert Comment

by:johnb6767
ID: 17846038
Never mind, alot prettier than what I had....
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 21

Author Comment

by:briancassin
ID: 17849227
gecko_au2003,


I tested your above script, very nice. I just wish I understood it better.


I do have a question, how would I make it so it silently does this (no confirmation box) and then write a log file named say "ProfileClearSuccessful" with the names of the accounts deleted ?

Or to run it silent I assume I can comment out the line that reads "msgbox "Profiles Deleted:" & vbCrLf & strMsg"

or would that cause an error ? We are going to run this in a logon script or as a scheduled task on each workstation since this is a consistent problem. So we probably don't want a box appearing to the users.



Also what is this case for ?

Case "supervisor.CSE2K"

   Case "supervisor"





johnb6767,

we already run the user profile hive cleanup, it works fair. Sometimes it does not clear out profiles they become locked that is why I was looking for a script or batch file that would take care of the problem.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17851595
ok instead of using msgbox you would need to create the file system object and create a text file ( aka log file ) that writes the strmsg which would show the deleted profiles ( Sometimes when I run that vbscript it will delete most of the profiles as sometimes there are some ntuser.dat files or some other files that cant be deleted because that user / user account will have the owner ship of them file or files.

What we do is literally logon to the station(s) and take owner ship of the folder or file(s) and then delete them so if you are left with profiles that shouldnt be there, then it may be the case that you will need to take ownership of them before being able to delete them so the script I provided isnt a 100% proof, but it should delete most of them for the most part and sometimes it will delete all of the ones it should do.

Give me about 5 mins or so and I will make it create a log file for you instead of the msgbox.
0
 
LVL 23

Accepted Solution

by:
gecko_au2003 earned 250 total points
ID: 17851676
Modified Script is below :

'---------

On Error Resume Next

Dim obtainfolder, PathFolder, strPath, x, strFolder()

DIM fso, NewsFile

Set fso = CreateObject("Scripting.FileSystemObject")

 strPath = "C:\Documents and Settings\"

 Set f = fso.GetFolder(strPath)

 x=0

 For Each fldrItem in f.SubFolders

  fldrName = fldrItem.name

  If Right(strPath,1) <> "\" Then

   PathFolder = strPath & "\" & fldrName

  Else

   PathFolder = strPath & fldrName

  End If
  Select Case fldrName

Case "Administrator", "All Users", "Default User", "LocalService", "NetworkService":

Case "supervisor.CSE2K"

Case "supervisor"

Case "sweepupd"

Case "sweepupd.CSE2K"

Case Else:
            ReDim Preserve strFolder(x)
            strFolder(x) = PathFolder
            x=x+1
    set obtainfolder = fso.GetFolder(PathFolder)    

    obtainfolder.Delete true      

 End Select

 Next

for x = 0 to ubound(strFolder)

  strMsg=strMsg & vbCrLf & strFolder(x)

next

Set NewsFile = fso.CreateTextFile("c:\Profile_Log.txt", True)  '<-- Change path of where you want logfile to be stored
NewsFile.WriteLine("Profile Deletion Log : ")
NewsFile.WriteLine
NewsFile.Write  "Profiles Deleted:" & vbCrLf & strMsg
NewsFile.Close

 ' Clean up objects

 Set fso = Nothing

 Set fc = Nothing

'-----------

Let me know if that is how you want it to be, as for these two case's here :

Case "supervisor.CSE2K"

   Case "supervisor"

Those are 2 accounts that we have on our domain that we dont want deleted when we run the script ie the name(s) of each folder(s) that we want to be left alone when we run the script.

As for what the case does is it matches each folder name with each of the case's and if it does not match any of the cases that are specified then it will delete those folders aka the profiles.

Let me know if that is ok for you :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

16 Experts available now in Live!

Get 1:1 Help Now