Detecting UserLogon status

Discussion in 'AutoCAD' started by Laurie Comerford, Jan 11, 2005.

  1. Hi,

    Further to the discussion under
    "Saving & Restoring User Info on Forms"

    above, I'm wondering if there is an API to detect the user's log on status.

    Is he an Administrator, a Power User, a Normal User, a Guest etc.?

    I expect I could attempt to write to something to HKLM and process any error
    which occurs, but this seems inelegant.


    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Jan 11, 2005
    #1
  2. Laurie Comerford

    bcoward Guest

    Laurie,

    To detect whether a user is administrator I've used the following code.

    Bear in mind that this code needs a reference to the MS Windows Installer object library but I think will suite your needs. I've used it successfully with Novell and NT.

    <CODE>
    Dim objInst As WindowsInstaller.Installer
    Dim objSession As WindowsInstaller.Session
    Dim strGuid As String
    Dim bIsAdmin As Boolean

    ' Won't instantiate using New keyword
    Set objInst = CreateObject("WindowsInstaller.Installer")

    With objInst
    .UILevel = msiUILevelNone
    strGuid = .Products(0)
    Set objSession = .OpenProduct(strGuid)
    End With

    ' Retrieve AdminUser property and convert to a boolean value
    With objSession
    bIsAdmin = CBool(.Property("AdminUser"))
    End With

    If bIsAdmin Then
    ' Do stuff
    MsgBox ("You are an Administrator...")
    Else
    ' Do nothing
    MsgBox ("You are not an Administrator...")
    End If

    ' Clean up
    Set objSession = Nothing
    Set objInst = Nothing
    </CODE>


    Hope this helps your wonderings.

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Jan 11, 2005
    #2
  3. I believe this can be acomplished using the
    Windows Management Instrumentation (WMI) API
     
    Jorge Jimenez, Jan 11, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.