Solved

Windows XP Local Locked User Profiles - AUTOMATED DELETION ?

Posted on 2006-10-31
8
745 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Disclosure: Use this tutorial only when no other options helps to get Windows XP running without any problems and you don't want to format the drive. The back up of the data is the responsible of the user, however there is a description of how t…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

14 Experts available now in Live!

Get 1:1 Help Now