Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Selective delete of profile using VBscript

Hi, I have a domain comprising of a mixture of W2k professional SP4 machines and WXP Professional SP2 machines.  All of these have a lot of unwanted local profiles on which it takes my colleagues and I a few days to delete.

Can anyone give me a hand writing a vbscript that will delete all of the local profiles from these workstations except for a select few.  E.g:

>All Users
>Default User

Is it possible to do a wild card for the administrator profile because there a lot of them e.g. administrator.001, administrator.bramcote etc.  Can i just put administrator* that would protect all of these accounts?

Many thanks in advance.

Ryan Powell
  • 2
1 Solution
you would first of all have to detect all the profiles on the computer and then from there do a select case or if statement to see which user profiles are not the ones you mentioned and that way you can determine which ones need deleted :


Here is a site that has 1 or 2 scripts with regards to deleting corrupted profiles, so that might give you an idea of how to delete them. I also have a script which I will post here that enumerates all users and groups on the computer, so that should help you to some extent :

' Get the name of the computer
str_Computer = WScript.CreateObject("WScript.Network").ComputerName

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oOutFile = oFSO.CreateTextFile("c:\usersandgroups.txt")

' Connect to the computer object
set oMachine = getObject("WinNT://" & str_Computer & ",computer")

' Set the filter to list users
oMachine.Filter = Array("group")

' For each group on the machine
For Each oGroup in oMachine
  oOutFile.writeline oGroup.Name

  ' For each user in the group
  For Each oUser in oGroup.Members
    ' display the user name
    oOutFile.writeline  vbTab & oUser.Name


Set oOutFile = Nothing
Set oFSO = Nothing

I would also suggest that you run a test with your newly created script ie do NOT delete the accounts, just get a message box to display to you which accounts are not the ones you mentioned, this way you can see which ones it would normally delete if you use the delete command, hence you are on the safe side and not deleting accounts left right and center:)

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now