How to access local security settings on Win2K (and above) computers

Posted on 2006-03-24
Last Modified: 2010-04-24
I am trying to write a MS VS.NET C++ (unmanaged code) application that will audit the settings available through the "Local Security Settings" (secpol.msc).  In particular, the password settings such as "Minimum password length".  This computer is not part of any domain.  I do not need to be able to change these settings, just to find out what they are.

A small code snippet would be preferable.
Question by:gmain
    1 Comment
    LVL 12

    Accepted Solution

    the following post may be relevant to your question.
    Date: Wed, 31 Mar 2004 11:46:54 -0600


    Reading is one thing, writing is another. The policy settings apply to the
    domain only, so there isn't much point altering these programmatically. They
    cannot be set for individual users. I don't remember seeing code to modify
    any Integer8 attributes. The relevant attributes are:

    attribute syntax
    --------- ------
    midPwdAge Integer8
    midPwdLength Integer
    lockoutDuration Integer8
    lockoutObservationWindow Integer8
    lockoutThreshold Integer

    The Integer8 attributes are 64-bit numbers. You must use the
    IADsLargeInteger interface to deal with the 64-bit numbers. In VBScript, you
    can read the values as follows:

    Option Explicit
    Dim objRootDSE, strDNSDomain, objDomain
    Dim objMinPWAge, lngMinPWAge
    Dim objDuration, lngDuration
    Dim objLockoutWin, lngLockoutWin

    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    Set objDomain = GetObject("LDAP://" & strDNSDomain)

    Wscript.Echo "Domain policy values"

    Set objMinPWAge = objDomain.minPwdAge
    lngMinPWAge = Int8ToSec(objMinPWAge) / (24 * 60 * 60)
    Wscript.Echo "Minimum password age in days: " & lngMinPWAge

    Wscript.Echo "Minimum password length: " & objDomain.minPwdLength

    Set objDuration = objDomain.lockoutDuration
    lngDuration = Int8ToSec(objDuration) / (60)
    Wscript.Echo "Lockout duration in minutes: " & lngDuration

    Set objLockoutWin = objDomain.lockoutObservationWindow
    lngLockoutWin = Int8ToSec(objLockoutWin) / (60)
    Wscript.Echo "Lockout window in minutes: " & lngLockoutWin

    Wscript.Echo "Lockout threshold: " & objDomain.lockoutThreshold

    Function Int8ToSec(objInt8)
    ' Function to convert Integer8 attributes from
    ' 64-bit numbers to seconds.
      Dim lngHigh, lngLow
      lngHigh = objInt8.HighPart
    ' Account for error in IADsLargeInteger property methods.
      lngLow = objInt8.LowPart
      If lngLow < 0 Then
        lngHigh = lngHigh + 1
      End If
      Int8ToSec = -(lngHigh * (2^32) + lngLow) / (10000000)
    End Function

    Microsoft MVP Scripting and ADSI
    HilltopLab web site -

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now