Announcement

Collapse
No announcement yet.

How to list ALL Users from Workgroup file with ADO?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to list ALL Users from Workgroup file with ADO?

    Hello,
    how to list ALL Users from Workgroup (system database) file with Microsoft.Jet.OLEDB.4.0?

    For example:
    I have system database (system.mdw) and any data source (data.mdb)
    Thanks.
    Yours sincerely

  • #2
    I found a solution:

    I made a few changes (red)

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    #INCLUDE "MSADO15.INC"
    
    
    FUNCTION PBMAIN () AS LONG
    
    LOCAL sWorkGroup   AS STRING
    LOCAL conn         AS ADODBConnection
    LOCAL rs           AS ADODBRecordset
    LOCAL vConnStr     AS VARIANT
    LOCAL vCursor      AS VARIANT
    LOCAL vConn        AS VARIANT
    LOCAL vIndex       AS VARIANT
    LOCAL rsFieldValue AS VARIANT
    LOCAL rsEnds       AS VARIANT
    LOCAL sReading     AS STRING
    [COLOR="Red"]LOCAL vIndex1       AS VARIANT
    LOCAL rsFieldValue1 AS VARIANT  
    LOCAL sBin         AS STRING
    LOCAL bBin         AS BYTE[/COLOR]
    
    sWorkGroup = "C:\TEMP\system.mdw"  [COLOR="Red"]' workgroup-file, security high? -> in vConnStr have to add "User Id=...;Password=...;"[/COLOR]
    LET vCursor  = %adUseNone
    LET vConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=" + sWorkGroup + ";Data Source=" + sWorkGroup + ";"
    
    SET conn = NEW ADODBConnection IN "ADODB.Connection"
    SET rs   = NEW ADODBRecordset  IN "ADODB.Recordset"
    
    OBJECT LET conn.CursorLocation = vCursor
    OBJECT LET conn.ConnectionString = vConnStr
    OBJECT CALL conn.Open
    IF OBJRESULT OR ERR THEN
        MSGBOX "Error in connection" & $CRLF & _
        "Object Result = " & STR$(OBJRESULT) & ";" & $CRLF & _
        "ERR = " & STR$(ERR)
        EXIT FUNCTION
    END IF
    
    LET vConnStr = "SELECT * FROM MSysAccounts IN " + CHR$(34) + _
    sWorkGroup  + CHR$(34) + " WHERE (MSysAccounts.Name <> " + CHR$(34) + "Users" + CHR$(34) + _
    " AND MSysAccounts.Name <> " + CHR$(34) + "Engine" + CHR$(34) + _
    " AND MSysAccounts.Name <> " + CHR$(34) + "Creator" + CHR$(34) + _
    " AND MSysAccounts.Name <> " + CHR$(34) + "Admins" + CHR$(34) + ") ORDER BY MSysAccounts.Name;"
    
    SET vConn = conn
    OBJECT LET rs.ActiveConnection = vConn
    OBJECT LET rs.Source = vConnStr
    OBJECT CALL rs.Open
    IF OBJRESULT OR ERR THEN
        MSGBOX "Error during opening recordset" & $CRLF & _
        "Object Result = " & STR$(OBJRESULT) & ";" & $CRLF & _
        "ERR = " & STR$(ERR)
        GOTO Ends
    END IF
    
    OBJECT CALL rs.MoveFirst
    DO
      [COLOR="Red"]sReading = "User: "[/COLOR]
      LET vIndex = "name"
      [COLOR="Red"]LET vIndex1 = "fgroup"[/COLOR]
      OBJECT GET rs.Fields.Item(vIndex).Value TO rsFieldValue
      [COLOR="Red"]OBJECT GET rs.Fields.Item(vIndex1).Value TO rsFieldValue1
      sBin = BIN$(VARIANT#(rsFieldValue1))
      bBin = VAL(RIGHT$(sBin,1))
      IF bBin THEN sReading = "Group: "[/COLOR]
      sReading = sReading + VARIANT$(rsFieldValue)
      [COLOR="Red"]IF TRIM$(VARIANT$(rsFieldValue)) <> "" THEN MSGBOX sReading[/COLOR]
      OBJECT GET rs.EOF TO rsEnds
      OBJECT CALL rs.MoveNext
    LOOP UNTIL VARIANT#(rsEnds) > 0
    
    OBJECT CALL rs.Close
    SET rs = NOTHING
    Ends:
    OBJECT CALL conn.Close
    SET conn = NOTHING
    MSGBOX "END..."
    
    END FUNCTION
    Last edited by Alexander Holzer; 27 Feb 2008, 02:15 PM.
    Yours sincerely

    Comment

    Working...
    X