VBscript to create a txt file that shows disabled/locked user accounts

Posted on 2008-11-05
Last Modified: 2012-05-05
Hi Experts:
I am in need a VBscript to create a txt file that shows me all disabled/locked user accounts. The server is not a member of domain.
Thanks in advance for your help!
Question by:changjia
    LVL 1

    Expert Comment

    Have you tried searching the Microsoft script center?

    you will find the source code for the script you are looking for but you may need to modify it depending upon your custom requirements.
    LVL 38

    Accepted Solution

    Paste the script below into a text file with a .vbs extension.  Customize the value of the strComputer variable with the name of the target computer.  Running it will write results to a text file.

    Const ForWriting = 2
    strComputer = "servername"
    strLog = "log.txt"
    On Error Resume Next
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLog = objFSO.OpenTextFile(strLog, ForWriting, True)
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE LocalAccount = 'True'")
    For Each objUser In colItems
        If objUser.Disabled Then
            objLog.WriteLine objUser.Name & ",disabled"
        ElseIf objUser.Lockout Then
            objLog.WriteLine objUser.Name & ",locked out"
        End If

    Open in new window


    Author Comment


    You are awesome!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now