Solved

Windows XP Local Locked User Profiles - AUTOMATED DELETION ?

Posted on 2006-10-31
8
747 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 7 Share with XP 22 180
Error login w2012 domain 6 84
in what format to convert 4 k without losing quality? 12 29
MMC - Computer Management / Display Properties 3 14
Can you find a fax from a vendor you saved a decade ago in seconds? Have you ever cursed your PC under your breath during an audit because you couldn’t find the requested statement or driver history?  If you answered no to the first question or yes …
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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