none
VBscript to delete local user account except built-in account and specified account RRS feed

  • Question

  • Can i have a vbscript to remove local user accounts except "built-in" and "specified user" accounts, builtin accounts are renamed to different one. so we should not mention "Administrator" and "Guest" in the script.

    prakash

    Thursday, May 14, 2015 12:44 PM

Answers

  • Can i have a vbscript to remove local user accounts except "built-in" and "specified user" accounts, builtin accounts are renamed to different one. so we should not mention "Administrator" and "Guest" in the script.

    prakash

     I Have completed this activity by using below script, this will exclude "Built-in"accounts and "ASP" mentioned in script, No need to specify "Buit-in" account as script can't delete it.

    On Error Resume Next
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName
    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    colAccounts.Filter = Array("user")
    For Each objUser In colAccounts
    If LCase(objUser.Name) = lCase("ASP") Then
    '// do nothing
    Else
    Call colAccounts.delete("User",objuser.name)
    End If
    On Error Resume Next
    Next


    prakash


    Tuesday, May 19, 2015 5:46 AM

All replies

  • Hi,

    Prewritten scripts can be found in the repository here:

    https://gallery.technet.microsoft.com/scriptcenter

    If you don't find what you're after and you can't write your own, you can request a script here:

    https://gallery.technet.microsoft.com/scriptcenter/site/requests

    I suggest skipping VBScript and using this an excuse to start learning PowerShell instead:

    http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx

    Let us know if you have any specific questions.


    Don't retire TechNet! - (Don't give up yet - 13,225+ strong and growing)

    Thursday, May 14, 2015 2:00 PM
  • this was also asked a couple days ago, and there are a couple of different solutions:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/c202d746-ea31-49e6-969b-61b95a91f20e/script-to-look-up-users-sid-and-then-delete-entry-from-registry-profilelist?forum=ITCG

    Thursday, May 14, 2015 3:21 PM
  • Can i have a vbscript to remove local user accounts except "built-in" and "specified user" accounts, builtin accounts are renamed to different one. so we should not mention "Administrator" and "Guest" in the script.

    prakash

     I Have completed this activity by using below script, this will exclude "Built-in"accounts and "ASP" mentioned in script, No need to specify "Buit-in" account as script can't delete it.

    On Error Resume Next
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName
    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    colAccounts.Filter = Array("user")
    For Each objUser In colAccounts
    If LCase(objUser.Name) = lCase("ASP") Then
    '// do nothing
    Else
    Call colAccounts.delete("User",objuser.name)
    End If
    On Error Resume Next
    Next


    prakash


    Tuesday, May 19, 2015 5:46 AM