Get Windows Active Directory Groups

Share your advanced PureBasic knowledge/code with the community.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Get Windows Active Directory Groups

Post by flaith »

UPDATE 12.03.2010 : Now you can have several DC in a pref file :mrgreen:
UPDATE 23.02.2010 : Now you can have several DC in a datasection

People Hi :)

it's just for a use with Active Directory to get informations about user and his groups in a network

Version with DC in a DataSection:

Code: Select all

; Voir aussi pour ADSI (Active Directory Service Interface)
; http://msdn.microsoft.com/en-us/library/aa772218%28VS.85%29.aspx
; pour essayer de récupérer adresse email de l'utilisateur

; Declaration
Declare ClearHours()
Declare MakeImgHours()

;lm.h
;-lmaccess.h 
;http://www.codase.com/search/display?file=L2dlbnRvbzIvdmFyL3RtcC9yZXBvcy9jb2Rhc2UuamF2YS93d3cud2luZWhxLmNvbS93aW5lL2luY2x1ZGUvbG1hY2Nlc3MuaA==&lang=c%2B%2B
;ou
;http://doc.ddart.net/msdn/header/include/lm.h.html
#TIMEQ_FOREVER                      = -1

#UF_SCRIPT                          = $000001
#UF_ACCOUNTDISABLE                  = $000002
#UF_HOMEDIR_REQUIRED                = $000008
#UF_LOCKOUT                         = $000010
#UF_PASSWD_NOTREQD                  = $000020
#UF_PASSWD_CANT_CHANGE              = $000040
#UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = $000080
#UF_TEMP_DUPLICATE_ACCOUNT          = $000100
#UF_NORMAL_ACCOUNT                  = $000200
#UF_INTERDOMAIN_TRUST_ACCOUNT       = $000800
#UF_WORKSTATION_TRUST_ACCOUNT       = $001000
#UF_SERVER_TRUST_ACCOUNT            = $002000
#UF_DONT_EXPIRE_PASSWD              = $010000
#UF_MNS_LOGON_ACCOUNT               = $020000
#UF_SMARTCARD_REQUIRED              = $040000
#UF_TRUSTED_FOR_DELEGATION          = $080000
#UF_NOT_DELEGATED                   = $100000
#UF_USE_DES_KEY_ONLY                = $200000
#UF_DONT_REQUIRE_PREAUTH            = $400000
#UF_PASSWORD_EXPIRED                = $800000

;-Enumerations
; Windows
Enumeration
  #WIN_GETADGROUPS
  #WIN_DAYS
  #FONT_EDITOR
  #FONT_HOURS
  #FONT_NAME
EndEnumeration

; Gadgets
Enumeration
  ;WIN_GETADGROUPS
  #LABEL_USER_LOGIN
  #USER_LOGIN
  #BUTTON_OK
  #LABEL_REMARKS

  #LABEL_INFO_USER
  #USER

  #LABEL_HOURS
  #LABEL_CLICK_HOURS

  #LABEL_GROUP
  #GROUPS

  ;WIN_DAYS
  #Frame3D_IMAGE
  #Frame3D_WIN_DAYS
  #Image_DAYS

  #LABEL_LOGIN_NAME
  #LABEL_SEP

  #Frame3D_HOURS
  #Text_ALL_HOURS

  #Frame3D_DIMANCHE
  #Text_DIMANCHE
  #Frame3D_LUNDI
  #Text_LUNDI
  #Frame3D_MARDI
  #Text_MARDI
  #Frame3D_MERCREDI
  #Text_MERCREDI
  #Frame3D_JEUDI
  #Text_JEUDI
  #Frame3D_VENDREDI
  #Text_VENDREDI
  #Frame3D_SAMEDI
  #Text_SAMEDI
  #Image_Hours
EndEnumeration

Enumeration 100
  #LOGIN
  #IMG_HOURS
EndEnumeration

; DataSection
DataSection

  dataDomain:
            ;Domain       Name of the
            ;Controller   Domain
    Data.s  "FIRSTDC",   "DC_FIRST"
    Data.s  "SECONDDC",   "DC_SECOND"
    Data.s  "THIRDDC",   "DC_THIRD"
    Data.s  "FOURTHDC",   "DC_FOURTH"
    Data.s  "@@@@@",      "<NONE>"

EndDataSection

;-Constantes
#_IWIDTH                = 370
#_IHEIGHT               = 385
; GroupAD
#OK_AD                  = "[AD_OK]"
#PS                     = SizeOf(Integer)
#MAX_PREFERRED_LENGTH   = -1

;Version
#APPLI_VERSION          = "0.9.1"
#LAST_DATE              = "23.02.10"
;Programmer
#PROGRAMMER             = "Nicolas Djurovic"

;constantes login hours
#WIDTH_BOX              =  10
#HEIGHT_BOX             =  25
#DEB_X                  = 105
#DEB_Y                  =  65
#WIDTH_IMG              = 240
#HEIGHT_IMG             = 175

;structures Login hours
Structure sHours
  first.l         ;1er tiers de la journée (0:00 à 7:59)
  second.l        ;2eme tiers de la journée (8:00 à 15:59)
  third.l         ;3eme tiers de la journée (16:00 à 23:59)
EndStructure

;-Structures AD
Structure sGROUPE
  UserID.s
  Group.s
EndStructure

;http://msdn.microsoft.com/en-us/library/aa371338%28VS.85%29.aspx
Structure sUSER
  UserID.s
  Domaine.s
  DomaineName.s
  Fullname.s
  Comment.s
  AcctExpires.l     ; Indicates when the account expires. This value is stored As the number of seconds elapsed since 00:00:00, January 1, 1970, GMT. ;
                    ; A value of TIMEQ_FOREVER indicates that the account never expires.
  HomeDir.s
  Flag.i
  ScriptPath.s
  HomeDirDrive.s
  PassExpired.l
  Privilege.l

  ; Pointer to a 21-byte (168 bits) bit string that specifies the times during which the user can log on. 
  ; Each bit represents a unique hour in the week, in Greenwich Mean Time (GMT).
  ; The first bit (bit 0, word 0) is Sunday, 0:00 To 0:59
  ; The second bit (bit 1, word 0) is Sunday, 1:00 to 1:59
  ; and so on. 
  ; Note that bit 0 in word 0 represents Sunday from 0:00 to 0:59 only if you are in the GMT time zone. 
  ; In all other cases you must adjust the bits according to your time zone offset 
  ; (for example, GMT minus 8 hours for Pacific Standard Time).
  
  ;*ptrLongonH
  LongonHours.a[21]
EndStructure

Structure sDomain
  Controller.s
  Name.s
EndStructure

;-Variables globales
;Global _COMPILE_COUNT.s  = RSet(Hex(#PB_Editor_CompileCount),4,"0")
;Global _BUILD_COUNT.s    = RSet(Hex(#PB_Editor_BuildCount),4,"0")

Global NewList UserGroups.sGROUPE()
Global NewList UserInfo.sUSER()
Global NewList Domain.sDomain()

Global domainesuivant = #False

Global CurrentName.s = ""

;Login hours
Global Dim tblHours.a(23,6)   ;nbcol x nblignes soit 24 colonnes par 7 lignes (24h / 7jours)
Global Dim tblDays.sHours(6)

;-Procedures
Procedure InitDomain()
Restore dataDomain
Read.s tmp1$
  While tmp1$ <> "@@@@@"
    Read.s tmp2$
    AddElement(Domain())
      Domain()\Controller = tmp1$
      Domain()\Name       = tmp2$
    Read.s tmp1$
  Wend

  AddElement(Domain())
    Domain()\Controller = tmp1$
    Domain()\Name       = "<NONE>"
EndProcedure

;Conversion des 21 octets de 8 bit en 24 colonnes par 7 lignes
Procedure ClearHours()
Protected heure, day

  For day = 0 To 6
    For heure = 0 To 23
      tblHours(heure,day) = 0
    Next heure
  Next day

 MakeImgHours()
 CurrentName = ""
EndProcedure

Procedure ConvertLogonHours()
Protected i.a, j.a, bit.a, octet.a, onebit.a, valuebit.a
Protected heure.a, day.a = 0
Protected Dim tblOctet.a(2)

  FirstElement(UserInfo())
  ind_day = 0

  ;1ere conversion
  For i = 0 To 20 Step 3
    tblDays(ind_day)\first  = UserInfo()\LongonHours[i]
    tblDays(ind_day)\second = UserInfo()\LongonHours[i+1]
    tblDays(ind_day)\third  = UserInfo()\LongonHours[i+2]
    ind_day + 1
  Next i

  ;Conversion finale
  For i = 0 To 6
    heure = 0
    tblOctet(0) = tblDays(i)\first
    tblOctet(1) = tblDays(i)\second
    tblOctet(2) = tblDays(i)\third

    For j = 0 To 2
      octet = tblOctet(j)
      valuebit = %10000000
      For bit = 0 To 7
        onebit = octet & valuebit
        If onebit
          tblHours(heure,day) = 1
        Else
          tblHours(heure,day) = 0
        EndIf
        valuebit >> 1
        heure + 1
      Next bit
    Next j

    day + 1

  Next i

EndProcedure

Procedure OpenWindow_Window_DAYS(X,Y)

  If OpenWindow(#WIN_DAYS, X, Y, #WIDTH_IMG+85+22, 248, "", #PB_Window_BorderLess, WindowID(#WIN_GETADGROUPS))
    Frame3DGadget(#Frame3D_WIN_DAYS, 0, 0 ,#WIDTH_IMG+85+22, 248, "", #PB_Frame3D_Flat)
      TextGadget   (#LABEL_LOGIN_NAME , 10,  5, #WIDTH_IMG+85, 20, "Logon Hours for "+CurrentName)
      SetGadgetFont(#LABEL_LOGIN_NAME , FontID(#FONT_NAME))
    TextGadget(#LABEL_SEP, 1, 27 ,603, 1, "", #WS_DLGFRAME*2)

    ContainerGadget(#Frame3D_HOURS, 85+11, 36, #WIDTH_IMG+2, 20, #PB_Container_Single)
      TextGadget   (#Text_ALL_HOURS   , 0, 0, #WIDTH_IMG, 20, "0 • 2 • 4 • 6 • 8 •10•12•14•16•18•20•22• 0")
      SetGadgetFont(#Text_ALL_HOURS, FontID(#FONT_HOURS))
    CloseGadgetList()

    ContainerGadget(#Frame3D_IMAGE, 10, 60, #WIDTH_IMG+85+3, #HEIGHT_IMG+3, #PB_Container_Single)
      Frame3DGadget(#Frame3D_DIMANCHE , -1, -1, 86, 27, "", #PB_Frame3D_Single)
        TextGadget (#Text_DIMANCHE    ,  1,  5, 80, 25, "Dimanche",#PB_Text_Center)
      Frame3DGadget(#Frame3D_LUNDI    , -1, 25, 86, 26, "", #PB_Frame3D_Single)
        TextGadget (#Text_LUNDI       ,  1, 31, 80, 25, "Lundi",#PB_Text_Center)
      Frame3DGadget(#Frame3D_MARDI    , -1, 50, 86, 26, "", #PB_Frame3D_Single)
        TextGadget (#Text_MARDI       ,  1, 56, 80, 25, "Mardi",#PB_Text_Center)
      Frame3DGadget(#Frame3D_MERCREDI , -1, 75, 86, 26, "", #PB_Frame3D_Single)
        TextGadget (#Text_MERCREDI    ,  1, 81, 80, 25, "Mercredi",#PB_Text_Center)
      Frame3DGadget(#Frame3D_JEUDI    , -1,100, 86, 26, "", #PB_Frame3D_Single)
        TextGadget (#Text_JEUDI       ,  1,106, 80, 25, "Jeudi",#PB_Text_Center)
      Frame3DGadget(#Frame3D_VENDREDI , -1,125, 86, 26, "", #PB_Frame3D_Single)
        TextGadget (#Text_VENDREDI    ,  1,131, 80, 25, "Vendredi",#PB_Text_Center)
      Frame3DGadget(#Frame3D_SAMEDI   , -1,150, 86, 27, "", #PB_Frame3D_Single)
        TextGadget (#Text_SAMEDI      ,  1,156, 80, 25, "Samedi",#PB_Text_Center)
      ImageGadget  (#Image_Hours, 85, 0, #WIDTH_IMG, #HEIGHT_IMG, ImageID(#IMG_HOURS), 0)
    CloseGadgetList()
  EndIf
EndProcedure

Procedure DrawGrid()
  For i = 0 To #WIDTH_IMG Step #WIDTH_BOX
    LineXY(i, 0, i, #HEIGHT_IMG, $000000)
  Next i

  For j = 0 To #HEIGHT_IMG Step #HEIGHT_BOX
    LineXY(0, j, #WIDTH_IMG, j, $000000)
  Next j
EndProcedure

Procedure InitImages()
  CreateImage(#LOGIN,#WIDTH_BOX,#HEIGHT_BOX)  
  CreateImage(#IMG_HOURS,#WIDTH_IMG+1,#HEIGHT_IMG+1)

  StartDrawing(ImageOutput(#LOGIN))
    Box(0,0,#WIDTH_BOX,#HEIGHT_BOX,RGB( 52,126,203))
  StopDrawing()

  StartDrawing(ImageOutput(#IMG_HOURS))
    Box(0,0,#WIDTH_IMG,#HEIGHT_IMG,RGB(255,255,255))
    DrawGrid()
  StopDrawing()
EndProcedure

Procedure MakeImgHours()
  StartDrawing(ImageOutput(#IMG_HOURS))
    Box(0,0,#WIDTH_IMG,#HEIGHT_IMG,RGB(255,255,255))
    For colonne = 0 To 23
      For ligne = 0 To 6
        val = tblHours(colonne,ligne)
        If val = 1
          DrawImage(ImageID(#LOGIN), (#WIDTH_BOX * colonne), (#HEIGHT_BOX * ligne))
        EndIf
      Next ligne
    Next colonne
    DrawGrid()
  StopDrawing()
EndProcedure

;-Gestion de l'AD
Procedure.s GetUserGroupAD(UserAD.s)
Protected *pBuf3.USER_INFO_3, *groups, dcname.s, entries.i, void.i
Protected *dcname = AllocateMemory(256)
Protected *buffer = AllocateMemory(1026)
Protected GetInfo.i, GetGroups.i

Protected Result.s = #OK_AD

	PokeS(*buffer, UserAD, -1, #PB_Unicode)

  ResetList(Domain())
  NextElement(Domain())

  While Domain()\Controller <> "@@@@@"
  	PokeS(*dcname, Domain()\Controller, -1, #PB_Unicode)
  	dcname = PeekS(*dcname, -1, #PB_Unicode)
  	Debug dcname
  
  	If Left(dcname, 2) = "\\"
	  	dcname = Mid(dcname, 3)
	  EndIf

    GetInfo = NetUserGetInfo_(*dcname, *buffer, 3, @*pBuf3)
    If GetInfo = 0            ; found a user
      AddElement(UserInfo())
        UserInfo()\UserID       = UserAD
        UserInfo()\Domaine      = dcname
        UserInfo()\DomaineName  = Domain()\Name
        UserInfo()\Fullname     = PeekS(*pBuf3\usri3_full_name, -1, #PB_Unicode)
        UserInfo()\Comment      = PeekS(*pBuf3\usri3_comment, -1, #PB_Unicode)
        UserInfo()\AcctExpires  = *pBuf3\usri3_acct_expires
        UserInfo()\HomeDir      = PeekS(*pBuf3\usri3_home_dir, -1, #PB_Unicode)
        UserInfo()\ScriptPath   = PeekS(*pBuf3\usri3_script_path, -1, #PB_Unicode)
        UserInfo()\HomeDirDrive = PeekS(*pBuf3\usri3_home_dir_drive, -1, #PB_Unicode)
        UserInfo()\PassExpired  = *pBuf3\usri3_password_expired
        UserInfo()\Flag         = *pBuf3\usri3_flags
        UserInfo()\Privilege    = *pBuf3\usri3_priv
        *ptrLongonH             = *pBuf3\usri3_logon_hours
        For i = 0 To 20
          UserInfo()\LongonHours[i] = PeekA(*ptrLongonH + i)
        Next i
  
      CurrentName = Trim(UserInfo()\Fullname)

      ConvertLogonHours()
      MakeImgHours()

    	GetGroups = NetUserGetGroups_(*dcname, *buffer, 0, @*groups, #MAX_PREFERRED_LENGTH, @entries, @void)
    	If GetGroups = 0
    		entries = (entries * #PS) - #PS
    		For i = 0 To entries Step #PS
    			AddElement(UserGroups())
     				UserGroups()\UserID = UserAD
     				UserGroups()\Group  = PeekS(PeekI(*groups + i), -1, #PB_Unicode)
    		Next
        SortStructuredList(UserGroups(), #PB_Sort_Ascending, OffsetOf(sGROUPE\Group), #PB_Sort_String)
        SetGadgetText(#LABEL_GROUP, "User groups ("+Str(ListSize(UserGroups()))+") :")
    
    		NetApiBufferFree_(*groups)
    	Else
    		ProcedureReturn Str(GetGroups)
    	EndIf
    
    	NetApiBufferFree_(*dcname)
    
      FreeMemory(*buffer)
    
      ProcedureReturn Result
      Break
    EndIf
    NextElement(Domain())
  Wend

  ProcedureReturn Str(GetInfo)

EndProcedure

Procedure ViewGroups(UserAD.s)
  ClearGadgetItems(#USER)   : ClearList(UserInfo())
  ClearGadgetItems(#GROUPS) : ClearList(UserGroups())
  ResetList(Domain())

  ;UserAD = Left(UserAD,8)
  SetGadgetText(#USER_LOGIN, UserAD)
  
  If Left(UserAD,1) = "?"
    AddGadgetItem(#USER, -1, "Information/About ...")
    AddGadgetItem(#USER, -1, "----GeWAD - Get Windows Active Directory Groups")
    AddGadgetItem(#USER, -1, "----"+#PROGRAMMER+" - "+#LAST_DATE+" - Version "+#APPLI_VERSION)
    AddGadgetItem(#USER, -1, "----300909c"+_COMPILE_COUNT+"b"+_BUILD_COUNT)
    SetGadgetText(#USER_LOGIN, "")
    ClearHours()
    ProcedureReturn 
  EndIf

  If UserAD <> ""
    rs$ = GetUserGroupAD(UserAD)
    If rs$ = #OK_AD
      ForEach UserInfo()
        AddGadgetItem(#USER, -1, "Name   : "+UserInfo()\Fullname+" ("+UserInfo()\DomaineName+")")
        AddGadgetItem(#USER, -1, "Comment: "+UserInfo()\Comment)

        If UserInfo()\AcctExpires = #TIMEQ_FOREVER
          AddGadgetItem(#USER, -1, "Account: never expires")
        Else
          AddGadgetItem(#USER, -1, "Account: expires "+FormatDate("%dd/%mm/%yyyy",UserInfo()\AcctExpires))
        EndIf

        If UserInfo()\Flag & #UF_LOCKOUT  = #UF_LOCKOUT
          AddGadgetItem(#USER, -1, "--- Account: is locked out")
        EndIf

        If UserInfo()\flag & #UF_ACCOUNTDISABLE = #UF_ACCOUNTDISABLE
          AddGadgetItem(#USER, -1, "--- Account: is disabled")
        EndIf

        If UserInfo()\PassExpired <> 0
          AddGadgetItem(#USER, -1, "--- Password: has expired")
        EndIf

        AddGadgetItem(#USER, -1, "Home   : "+UserInfo()\HomeDir)
        AddGadgetItem(#USER, -1, "Script : "+UserInfo()\ScriptPath)
      Next
  
      ForEach UserGroups()
        AddGadgetItem(#GROUPS, -1, UserGroups()\Group)
      Next

    Else
      If rs$ = "2221"
        ClearHours()
        AddGadgetItem(#USER, -1, "Error #"+rs$)
        AddGadgetItem(#USER, -1, "----Login `"+UserAD+"´ not found.")
        AddGadgetItem(#USER, -1, "----Try putting a valid login !")
      EndIf
    EndIf
  Else
    ClearHours()
    AddGadgetItem(#USER, -1, "Error")
    AddGadgetItem(#USER, -1, "----Login empty.")
    AddGadgetItem(#USER, -1, "----Try putting a valid login !")
  EndIf

  ;Select login area
  SetActiveGadget(#USER_LOGIN)
  SendMessage_(GadgetID(#USER_LOGIN),#EM_SETSEL,0,-1)
EndProcedure

;-CallBack
Procedure WinCallback(hwnd, msg, wParam, lParam)
Static gadget
Protected pt.POINT
Protected result = #PB_ProcessPureBasicEvents

  pt\x = WindowMouseX(#WIN_GETADGROUPS)
  pt\y = WindowMouseY(#WIN_GETADGROUPS)
	Select msg
		Case #WM_LBUTTONDOWN
			gadget = GetDlgCtrlID_(ChildWindowFromPoint_(hwnd, pt\x + pt\y << 32))

			Select gadget
				Case #LABEL_CLICK_HOURS
					OpenWindow_Window_DAYS(DesktopMouseX() - (#WIDTH_IMG+85+30), DesktopMouseY() - (248/2));(514, 413)
			EndSelect

		Case #WM_LBUTTONUP
			Select gadget
				Case #LABEL_CLICK_HOURS
				  If IsWindow(#WIN_DAYS) : CloseWindow(#WIN_DAYS) : EndIf
					gadget = -1
			EndSelect

		Case #WM_MOUSEMOVE
			If GetAsyncKeyState_(#VK_LBUTTON)
				If gadget = #LABEL_CLICK_HOURS
					location = GetDlgCtrlID_(ChildWindowFromPoint_(hwnd, pt\x + pt\y << 32))
					If location = gadget
					  If IsWindow(#WIN_DAYS)
					    ResizeWindow(#WIN_DAYS, DesktopMouseX() - (#WIDTH_IMG+85+30), DesktopMouseY() - (248/2), #WIDTH_IMG+85+22, 248)
					  EndIf 
 					Else
 					  If IsWindow(#WIN_DAYS) : CloseWindow(#WIN_DAYS) : EndIf
					EndIf
				EndIf
			EndIf

	EndSelect

	ProcedureReturn result
EndProcedure

Procedure OpenWindow_WIN_GETADGROUPS(X,Y)
  If OpenWindow(#WIN_GETADGROUPS, X, Y, #_IWIDTH, #_IHEIGHT, "GeWAD - Get Windows Active Directory Groups", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    TextGadget(#LABEL_USER_LOGIN, 10, 7, 65, 15, "User Login :")
    StringGadget(#USER_LOGIN, 70, 5, 85, 18, "", #PB_String_UpperCase)
    ButtonGadget(#BUTTON_OK, 155, 5, 25, 18, "Ok")
    TextGadget(#LABEL_REMARKS, 185, 7, 150, 15, "(ou 'return')")

    TextGadget(#LABEL_INFO_USER, 10, 35, 110, 15, "User description :")
    EditorGadget(#USER, 10, 50, 350, 95, #PB_Editor_ReadOnly)

    TextGadget(#LABEL_CLICK_HOURS, #_IWIDTH - 125, 150, 15, 15, "",#WS_DLGFRAME/14-1)
    TextGadget(#LABEL_HOURS, #_IWIDTH - 105, 151, 120, 15, ": Click for login hours")

    TextGadget(#LABEL_GROUP, 10, 170, 110, 15, "User groups :")
    EditorGadget(#GROUPS, 10, 185, 350, 190, #PB_Editor_ReadOnly)
    SetGadgetFont(#USER, FontID(#FONT_EDITOR))
    SetGadgetFont(#GROUPS, FontID(#FONT_EDITOR))
  EndIf
EndProcedure

InitDomain()
InitImages()
LoadFont(#FONT_EDITOR, "Courier New", 8)
LoadFont(#FONT_HOURS, "Luncida Console", 10)
LoadFont(#FONT_NAME, "Luncida Console", 8, #PB_Font_Bold)

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Taille_Ecran.RECT, 0)
Largeur_Ecran = (Taille_Ecran\Right - Taille_Ecran\Left)-5
Hauteur_Ecran = (Taille_Ecran\Bottom - Taille_Ecran\top)-25
OpenWindow_WIN_GETADGROUPS(Largeur_Ecran-#_IWIDTH,Hauteur_Ecran-#_IHEIGHT)

SetWindowCallback(@WinCallback())

SetActiveGadget(#USER_LOGIN)
;http://msdn.microsoft.com/en-us/library/bb761607%28VS.85%29.aspx
SendMessage_(GadgetID(#USER_LOGIN), #EM_LIMITTEXT, 8, 0)   ;8 car max
; ou http://www.purebasic.fr/english/viewtopic.php?p=301303#p301303

;- Event loop
Repeat
  Select WaitWindowEvent()

    Case #PB_Event_ActivateWindow
      SetActiveGadget(#USER_LOGIN)
      SendMessage_(GadgetID(#USER_LOGIN),#EM_SETSEL,0,-1)

    Case #PB_Event_Gadget
      Select EventGadget()
        Case #BUTTON_OK
          ViewGroups(GetGadgetText(#USER_LOGIN))
      EndSelect

    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #WIN_GETADGROUPS
          CloseWindow(#WIN_GETADGROUPS)
          Break
      EndSelect

    Case #WM_KEYDOWN
      Select EventwParam()

        Case #VK_RETURN
          ViewGroups(GetGadgetText(#USER_LOGIN))

      EndSelect

  EndSelect
ForEver
Version with Domain Controller in a pref file :

Code: Select all

; Voir aussi pour ADSI (Active Directory Service Interface)
; http://msdn.microsoft.com/en-us/library/aa772218%28VS.85%29.aspx
; pour essayer de récupérer adresse email de l'utilisateur

; Declaration
Declare ClearHours()
Declare MakeImgHours()

;lm.h
;-lmaccess.h 
;http://www.codase.com/search/display?file=L2dlbnRvbzIvdmFyL3RtcC9yZXBvcy9jb2Rhc2UuamF2YS93d3cud2luZWhxLmNvbS93aW5lL2luY2x1ZGUvbG1hY2Nlc3MuaA==)=c%2B%2B
;ou
;http://doc.ddart.net/msdn/header/include/lm.h.html
#TIMEQ_FOREVER                      = -1

#UF_SCRIPT                          = $000001
#UF_ACCOUNTDISABLE                  = $000002
#UF_HOMEDIR_REQUIRED                = $000008
#UF_LOCKOUT                         = $000010
#UF_PASSWD_NOTREQD                  = $000020
#UF_PASSWD_CANT_CHANGE              = $000040
#UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = $000080
#UF_TEMP_DUPLICATE_ACCOUNT          = $000100
#UF_NORMAL_ACCOUNT                  = $000200
#UF_INTERDOMAIN_TRUST_ACCOUNT       = $000800
#UF_WORKSTATION_TRUST_ACCOUNT       = $001000
#UF_SERVER_TRUST_ACCOUNT            = $002000
#UF_DONT_EXPIRE_PASSWD              = $010000
#UF_MNS_LOGON_ACCOUNT               = $020000
#UF_SMARTCARD_REQUIRED              = $040000
#UF_TRUSTED_FOR_DELEGATION          = $080000
#UF_NOT_DELEGATED                   = $100000
#UF_USE_DES_KEY_ONLY                = $200000
#UF_DONT_REQUIRE_PREAUTH            = $400000
#UF_PASSWORD_EXPIRED                = $800000

;-Enumerations
; Windows
Enumeration
	#WIN_GETADGROUPS
	#WIN_DAYS
	#FONT_EDITOR
	#FONT_HOURS
	#FONT_NAME
EndEnumeration

; Gadgets
Enumeration
	;WIN_GETADGROUPS
	#LABEL_USER_LOGIN
	#USER_LOGIN
	#BUTTON_OK
	#LABEL_REMARKS

	#LABEL_INFO_USER
	#USER

	#LABEL_HOURS
	#LABEL_CLICK_HOURS

	#LABEL_GROUP
	#GROUPS

	;WIN_DAYS
	#Frame3D_IMAGE
	#Frame3D_WIN_DAYS
	#Image_DAYS

	#LABEL_LOGIN_NAME
	#LABEL_SEP

	#Frame3D_HOURS
	#Text_ALL_HOURS

	#Frame3D_DIMANCHE
	#Text_DIMANCHE
	#Frame3D_LUNDI
	#Text_LUNDI
	#Frame3D_MARDI
	#Text_MARDI
	#Frame3D_MERCREDI
	#Text_MERCREDI
	#Frame3D_JEUDI
	#Text_JEUDI
	#Frame3D_VENDREDI
	#Text_VENDREDI
	#Frame3D_SAMEDI
	#Text_SAMEDI
	#Image_Hours
EndEnumeration

Enumeration 100
	#LOGIN
	#IMG_HOURS
EndEnumeration

; DOMController.prefs
; [Entity]
; EntityOrder=Domain3,Domain1,Domain2,Domain5
; 
; [Domain1]
; Domain = 10.0.0.2
; Name = BOULDER Company
; Remark = Primary server
; 
; [Domain2]
; Domain = 10.0.0.3
; Name = BOULDER Company
; Remark = Secondary server
; 
; [Domain3]
; Domain = RORSCHACH
; Name = PSYCHO Company
; Remark = ^^
; 
; [Domain4]
; Domain = DC_VS230
; Name = SAGITTARUS
; Remark = 
; 
; [Domain5]
; Domain = DC_VS232
; Name = PISCES
; Remark = 
; 
; [Domain6]
; Domain = DC_VS234
; Name = CAPRICA
; Remark = Cylon control

;-Constantes
#FilePREFS              = "DOMController.prefs"
#_IWIDTH                = 370
#_IHEIGHT               = 385
; GroupAD
#OK_AD                  = "[AD_OK]"
#PS                     = SizeOf(Integer)
#MAX_PREFERRED_LENGTH   = -1

;Version
#APPLI_VERSION          = "0.10.0"
#LAST_DATE              = "12.03.10"
;Programmer
#PROGRAMMER             = "Nicolas Djurovic"

;constantes login hours
#WIDTH_BOX              =  10
#HEIGHT_BOX             =  25
#DEB_X                  = 105
#DEB_Y                  =  65
#WIDTH_IMG              = 240
#HEIGHT_IMG             = 175

;structures Login hours
Structure sHours
	first.l         ;1er tiers de la journée (0:00 à 7:59)
	second.l        ;2eme tiers de la journée (8:00 à 15:59)
	third.l         ;3eme tiers de la journée (16:00 à 23:59)
EndStructure

;-Structures AD
Structure sGROUPE
	UserID.s
	Group.s
EndStructure

;http://msdn.microsoft.com/en-us/library/aa371338%28VS.85%29.aspx
Structure sUSER
	UserID.s
	Domaine.s
	DomaineName.s
	Fullname.s
	Comment.s
	AcctExpires.l     ; Indicates when the account expires. This value is stored As the number of seconds elapsed since 00:00:00, January 1, 1970, GMT. ;
										; A value of TIMEQ_FOREVER indicates that the account never expires.
	HomeDir.s
	Flag.i
	ScriptPath.s
	HomeDirDrive.s
	PassExpired.l
	Privilege.l

	; Pointer to a 21-byte (168 bits) bit string that specifies the times during which the user can log on. 
	; Each bit represents a unique hour in the week, in Greenwich Mean Time (GMT).
	; The first bit (bit 0, word 0) is Sunday, 0:00 To 0:59
	; The second bit (bit 1, word 0) is Sunday, 1:00 to 1:59
	; and so on. 
	; Note that bit 0 in word 0 represents Sunday from 0:00 to 0:59 only if you are in the GMT time zone. 
	; In all other cases you must adjust the bits according to your time zone offset 
	; (for example, GMT minus 8 hours for Pacific Standard Time).
	
	;*ptrLongonH
	LongonHours.a[21]
EndStructure

Structure sDomain
	Controller.s
	Name.s
	Remark.s
EndStructure

;-Variables globales
;Global _COMPILE_COUNT.s  = RSet(Hex(#PB_Editor_CompileCount),4,"0")
;Global _BUILD_COUNT.s    = RSet(Hex(#PB_Editor_BuildCount),4,"0")

Global NewList UserGroups.sGROUPE()
Global NewList UserInfo.sUSER()
Global NewList Domain.sDomain()

Global domainesuivant = #False

Global CurrentName.s = ""

;Login hours
Global Dim tblHours.a(23,6)   ;nbcol x nblignes soit 24 colonnes par 7 lignes (24h / 7jours)
Global Dim tblDays.sHours(6)

;-Procedures
Procedure InitDomain()
Define.i i, tot_entite
Define.s EntityOrder
Protected NewList Entity.s()

  If OpenPreferences(#FilePREFS)

    PreferenceGroup("Entity")
      EntityOrder = ReadPreferenceString("EntityOrder", "")
      tot_entite = CountString(EntityOrder, ",")

      For i = 1 To tot_entite + 1
        AddElement(Entity())
        Entity() = StringField(EntityOrder,i,",")
      Next i

    ForEach Entity()
      PreferenceGroup(Entity())
        AddElement(Domain())
          Domain()\Controller = ReadPreferenceString("Domain", "")
          Domain()\Name       = ReadPreferenceString("Name", "")
          Domain()\Remark     = ReadPreferenceString("Remark", "")
    Next
      
    ClosePreferences()

    AddElement(Domain())
      Domain()\Controller = "@@@@@"
      Domain()\Name       = ""
      Domain()\Remark     = ""
  Else
    MessageRequester("Error","File '"+#FilePREFS+"' not found !!!")
    End
  EndIf
EndProcedure

;Conversion des 21 octets de 8 bit en 24 colonnes par 7 lignes
Procedure ClearHours()
Protected heure, day

	For day = 0 To 6
		For heure = 0 To 23
			tblHours(heure,day) = 0
		Next heure
	Next day

MakeImgHours()
CurrentName = ""
EndProcedure

Procedure ConvertLogonHours()
Protected i.a, j.a, bit.a, octet.a, onebit.a, valuebit.a
Protected heure.a, day.a = 0
Protected Dim tblOctet.a(2)

	FirstElement(UserInfo())
	ind_day = 0

	;1ere conversion
	For i = 0 To 20 Step 3
		tblDays(ind_day)\first  = UserInfo()\LongonHours[i]
		tblDays(ind_day)\second = UserInfo()\LongonHours[i+1]
		tblDays(ind_day)\third  = UserInfo()\LongonHours[i+2]
		ind_day + 1
	Next i

	;Conversion finale
	For i = 0 To 6
		heure = 0
		tblOctet(0) = tblDays(i)\first
		tblOctet(1) = tblDays(i)\second
		tblOctet(2) = tblDays(i)\third

		For j = 0 To 2
			octet = tblOctet(j)
			valuebit = %10000000
			For bit = 0 To 7
				onebit = octet & valuebit
				If onebit
					tblHours(heure,day) = 1
				Else
					tblHours(heure,day) = 0
				EndIf
				valuebit >> 1
				heure + 1
			Next bit
		Next j

		day + 1

	Next i

EndProcedure

Procedure OpenWindow_Window_DAYS(X,Y)

	If OpenWindow(#WIN_DAYS, X, Y, #WIDTH_IMG+85+22, 248, "", #PB_Window_BorderLess, WindowID(#WIN_GETADGROUPS))
		Frame3DGadget(#Frame3D_WIN_DAYS, 0, 0 ,#WIDTH_IMG+85+22, 248, "", #PB_Frame3D_Flat)
			TextGadget   (#LABEL_LOGIN_NAME , 10,  5, #WIDTH_IMG+85, 20, "Logon Hours for "+CurrentName)
			SetGadgetFont(#LABEL_LOGIN_NAME , FontID(#FONT_NAME))
		TextGadget(#LABEL_SEP, 1, 27 ,603, 1, "", #WS_DLGFRAME*2)

		ContainerGadget(#Frame3D_HOURS, 85+11, 36, #WIDTH_IMG+2, 20, #PB_Container_Single)
			TextGadget   (#Text_ALL_HOURS   , 0, 0, #WIDTH_IMG, 20, "0 • 2 • 4 • 6 • 8 •10•12•14•16•18•20•22• 0")
			SetGadgetFont(#Text_ALL_HOURS, FontID(#FONT_HOURS))
		CloseGadgetList()

		ContainerGadget(#Frame3D_IMAGE, 10, 60, #WIDTH_IMG+85+3, #HEIGHT_IMG+3, #PB_Container_Single)
			Frame3DGadget(#Frame3D_DIMANCHE , -1, -1, 86, 27, "", #PB_Frame3D_Single)
				TextGadget (#Text_DIMANCHE    ,  1,  5, 80, 25, "Dimanche",#PB_Text_Center)
			Frame3DGadget(#Frame3D_LUNDI    , -1, 25, 86, 26, "", #PB_Frame3D_Single)
				TextGadget (#Text_LUNDI       ,  1, 31, 80, 25, "Lundi",#PB_Text_Center)
			Frame3DGadget(#Frame3D_MARDI    , -1, 50, 86, 26, "", #PB_Frame3D_Single)
				TextGadget (#Text_MARDI       ,  1, 56, 80, 25, "Mardi",#PB_Text_Center)
			Frame3DGadget(#Frame3D_MERCREDI , -1, 75, 86, 26, "", #PB_Frame3D_Single)
				TextGadget (#Text_MERCREDI    ,  1, 81, 80, 25, "Mercredi",#PB_Text_Center)
			Frame3DGadget(#Frame3D_JEUDI    , -1,100, 86, 26, "", #PB_Frame3D_Single)
				TextGadget (#Text_JEUDI       ,  1,106, 80, 25, "Jeudi",#PB_Text_Center)
			Frame3DGadget(#Frame3D_VENDREDI , -1,125, 86, 26, "", #PB_Frame3D_Single)
				TextGadget (#Text_VENDREDI    ,  1,131, 80, 25, "Vendredi",#PB_Text_Center)
			Frame3DGadget(#Frame3D_SAMEDI   , -1,150, 86, 27, "", #PB_Frame3D_Single)
				TextGadget (#Text_SAMEDI      ,  1,156, 80, 25, "Samedi",#PB_Text_Center)
			ImageGadget  (#Image_Hours, 85, 0, #WIDTH_IMG, #HEIGHT_IMG, ImageID(#IMG_HOURS), 0)
		CloseGadgetList()
	EndIf
EndProcedure

Procedure DrawGrid()
	For i = 0 To #WIDTH_IMG Step #WIDTH_BOX
		LineXY(i, 0, i, #HEIGHT_IMG, $000000)
	Next i

	For j = 0 To #HEIGHT_IMG Step #HEIGHT_BOX
		LineXY(0, j, #WIDTH_IMG, j, $000000)
	Next j
EndProcedure

Procedure InitImages()
	CreateImage(#LOGIN,#WIDTH_BOX,#HEIGHT_BOX)  
	CreateImage(#IMG_HOURS,#WIDTH_IMG+1,#HEIGHT_IMG+1)

	StartDrawing(ImageOutput(#LOGIN))
		Box(0,0,#WIDTH_BOX,#HEIGHT_BOX,RGB( 52,126,203))
	StopDrawing()

	StartDrawing(ImageOutput(#IMG_HOURS))
		Box(0,0,#WIDTH_IMG,#HEIGHT_IMG,RGB(255,255,255))
		DrawGrid()
	StopDrawing()
EndProcedure

Procedure MakeImgHours()
	StartDrawing(ImageOutput(#IMG_HOURS))
		Box(0,0,#WIDTH_IMG,#HEIGHT_IMG,RGB(255,255,255))
		For colonne = 0 To 23
			For ligne = 0 To 6
				val = tblHours(colonne,ligne)
				If val = 1
					DrawImage(ImageID(#LOGIN), (#WIDTH_BOX * colonne), (#HEIGHT_BOX * ligne))
				EndIf
			Next ligne
		Next colonne
		DrawGrid()
	StopDrawing()
EndProcedure

;-Gestion de l'AD
Procedure.s GetUserGroupAD(UserAD.s)
Protected *pBuf3.USER_INFO_3, *groups, dcname.s, entries.i, void.i
Protected *dcname = AllocateMemory(256)
Protected *buffer = AllocateMemory(1026)
Protected GetInfo.i, GetGroups.i

Protected Result.s = #OK_AD

		PokeS(*buffer, UserAD, -1, #PB_Unicode)

	ResetList(Domain())
	NextElement(Domain())

	While Domain()\Controller <> "@@@@@"
			PokeS(*dcname, Domain()\Controller, -1, #PB_Unicode)
			dcname = PeekS(*dcname, -1, #PB_Unicode)
			Debug dcname
	
			If Left(dcname, 2) = "\\"
					dcname = Mid(dcname, 3)
			EndIf

		GetInfo = NetUserGetInfo_(*dcname, *buffer, 3, @*pBuf3)
		If GetInfo = 0            ; found a user
			AddElement(UserInfo())
				UserInfo()\UserID       = UserAD
				UserInfo()\Domaine      = dcname
				UserInfo()\DomaineName  = Domain()\Name
				UserInfo()\Fullname     = PeekS(*pBuf3\usri3_full_name, -1, #PB_Unicode)
				UserInfo()\Comment      = PeekS(*pBuf3\usri3_comment, -1, #PB_Unicode)
				UserInfo()\AcctExpires  = *pBuf3\usri3_acct_expires
				UserInfo()\HomeDir      = PeekS(*pBuf3\usri3_home_dir, -1, #PB_Unicode)
				UserInfo()\ScriptPath   = PeekS(*pBuf3\usri3_script_path, -1, #PB_Unicode)
				UserInfo()\HomeDirDrive = PeekS(*pBuf3\usri3_home_dir_drive, -1, #PB_Unicode)
				UserInfo()\PassExpired  = *pBuf3\usri3_password_expired
				UserInfo()\Flag         = *pBuf3\usri3_flags
				UserInfo()\Privilege    = *pBuf3\usri3_priv
				*ptrLongonH             = *pBuf3\usri3_logon_hours
				For i = 0 To 20
					UserInfo()\LongonHours[i] = PeekA(*ptrLongonH + i)
				Next i
	
			CurrentName = Trim(UserInfo()\Fullname)

			ConvertLogonHours()
			MakeImgHours()

				GetGroups = NetUserGetGroups_(*dcname, *buffer, 0, @*groups, #MAX_PREFERRED_LENGTH, @entries, @void)
				If GetGroups = 0
						entries = (entries * #PS) - #PS
						For i = 0 To entries Step #PS
								AddElement(UserGroups())
											UserGroups()\UserID = UserAD
											UserGroups()\Group  = PeekS(PeekI(*groups + i), -1, #PB_Unicode)
						Next
				SortStructuredList(UserGroups(), #PB_Sort_Ascending, OffsetOf(sGROUPE\Group), #PB_Sort_String)
				SetGadgetText(#LABEL_GROUP, "User groups ("+Str(ListSize(UserGroups()))+") :")
		
						NetApiBufferFree_(*groups)
				Else
						ProcedureReturn Str(GetGroups)
				EndIf
		
				NetApiBufferFree_(*dcname)
		
			FreeMemory(*buffer)
		
			ProcedureReturn Result
			Break
		EndIf
		NextElement(Domain())
	Wend

	ProcedureReturn Str(GetInfo)

EndProcedure

Procedure ViewGroups(UserAD.s)
	ClearGadgetItems(#USER)   : ClearList(UserInfo())
	ClearGadgetItems(#GROUPS) : ClearList(UserGroups())
	ResetList(Domain())

	;UserAD = Left(UserAD,8)
	SetGadgetText(#USER_LOGIN, UserAD)
	
	If Left(UserAD,1) = "?"
		AddGadgetItem(#USER, -1, "Information/About ...")
		AddGadgetItem(#USER, -1, "----GeWAD - Get Windows Active Directory Groups")
		AddGadgetItem(#USER, -1, "----"+#PROGRAMMER+" - "+#LAST_DATE+" - Version "+#APPLI_VERSION)
		AddGadgetItem(#USER, -1, "----300909c"+_COMPILE_COUNT+"b"+_BUILD_COUNT)

    ResetList(Domain())
    FirstElement(Domain())

    While Domain()\Controller <> "@@@@@"
      tmp1$ = Domain()\Controller
      tmp2$ = Domain()\Name
      tmp3$ = Domain()\Remark
      AddGadgetItem(#GROUPS, -1, "----"+tmp1$+#TAB$+tmp2$+#TAB$+tmp3$)
      NextElement(Domain())
    Wend

		SetGadgetText(#USER_LOGIN, "")
		ClearHours()
		ProcedureReturn 
	EndIf

	If UserAD <> ""
		rs$ = GetUserGroupAD(UserAD)
		If rs$ = #OK_AD
			ForEach UserInfo()
				AddGadgetItem(#USER, -1, "Name   : "+UserInfo()\Fullname+" ("+UserInfo()\DomaineName+")")
				AddGadgetItem(#USER, -1, "Comment: "+UserInfo()\Comment)

				If UserInfo()\AcctExpires = #TIMEQ_FOREVER
					AddGadgetItem(#USER, -1, "Account: never expires")
				Else
					AddGadgetItem(#USER, -1, "Account: expires "+FormatDate("%dd/%mm/%yyyy",UserInfo()\AcctExpires))
				EndIf

				If UserInfo()\Flag & #UF_LOCKOUT  = #UF_LOCKOUT
					AddGadgetItem(#USER, -1, "--- Account: is locked out")
				EndIf

				If UserInfo()\flag & #UF_ACCOUNTDISABLE = #UF_ACCOUNTDISABLE
					AddGadgetItem(#USER, -1, "--- Account: is disabled")
				EndIf

				If UserInfo()\PassExpired <> 0
					AddGadgetItem(#USER, -1, "--- Password: has expired")
				EndIf

				AddGadgetItem(#USER, -1, "Home   : "+UserInfo()\HomeDir)
				AddGadgetItem(#USER, -1, "Script : "+UserInfo()\ScriptPath)
			Next
	
			ForEach UserGroups()
				AddGadgetItem(#GROUPS, -1, UserGroups()\Group)
			Next

		Else
			If rs$ = "2221"
				ClearHours()
				AddGadgetItem(#USER, -1, "Error #"+rs$)
				AddGadgetItem(#USER, -1, "----Login `"+UserAD+"´ not found.")
				AddGadgetItem(#USER, -1, "----Try putting a valid login !")
			EndIf
		EndIf
	Else
		ClearHours()
		AddGadgetItem(#USER, -1, "Error")
		AddGadgetItem(#USER, -1, "----Login empty.")
		AddGadgetItem(#USER, -1, "----Try putting a valid login !")
	EndIf

	;Select login area
	SetActiveGadget(#USER_LOGIN)
	SendMessage_(GadgetID(#USER_LOGIN),#EM_SETSEL,0,-1)
EndProcedure

;-CallBack
Procedure WinCallback(hwnd, msg, wParam, lParam)
Static gadget
Protected pt.POINT
Protected result = #PB_ProcessPureBasicEvents

	pt\x = WindowMouseX(#WIN_GETADGROUPS)
	pt\y = WindowMouseY(#WIN_GETADGROUPS)

	Select msg
		Case #WM_LBUTTONDOWN
			gadget = GetDlgCtrlID_(ChildWindowFromPoint_(hwnd, pt\x + pt\y << 32))

			Select gadget
				Case #LABEL_CLICK_HOURS
					OpenWindow_Window_DAYS(DesktopMouseX() - (#WIDTH_IMG+85+30), DesktopMouseY() - (248/2));(514, 413)
			EndSelect

		Case #WM_LBUTTONUP
			Select gadget
				Case #LABEL_CLICK_HOURS
				  If IsWindow(#WIN_DAYS) : CloseWindow(#WIN_DAYS) : EndIf
					gadget = -1
			EndSelect

		Case #WM_MOUSEMOVE
			If GetAsyncKeyState_(#VK_LBUTTON)
				If gadget = #LABEL_CLICK_HOURS
					location = GetDlgCtrlID_(ChildWindowFromPoint_(hwnd, pt\x + pt\y << 32))
					If location = gadget
					  If IsWindow(#WIN_DAYS)
					    ResizeWindow(#WIN_DAYS, DesktopMouseX() - (#WIDTH_IMG+85+30), DesktopMouseY() - (248/2), #WIDTH_IMG+85+22, 248)
					  EndIf 
 					Else
 					  If IsWindow(#WIN_DAYS) : CloseWindow(#WIN_DAYS) : EndIf
					EndIf
				EndIf
			EndIf

	EndSelect

	ProcedureReturn result
EndProcedure

Procedure OpenWindow_WIN_GETADGROUPS(X,Y)
	If OpenWindow(#WIN_GETADGROUPS, X, Y, #_IWIDTH, #_IHEIGHT, "GeWAD - Get Windows Active Directory Groups", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
		TextGadget(#LABEL_USER_LOGIN, 10, 7, 65, 15, "User Login :")
		StringGadget(#USER_LOGIN, 70, 5, 85, 18, "", #PB_String_UpperCase)
		ButtonGadget(#BUTTON_OK, 155, 5, 25, 18, "Ok")
		TextGadget(#LABEL_REMARKS, 185, 7, 150, 15, "(ou 'return')")

		TextGadget(#LABEL_INFO_USER, 10, 35, 110, 15, "User description :")
		EditorGadget(#USER, 10, 50, 350, 95, #PB_Editor_ReadOnly)

		TextGadget(#LABEL_CLICK_HOURS, #_IWIDTH - 125, 150, 15, 15, "",#WS_DLGFRAME/14-1)
		TextGadget(#LABEL_HOURS, #_IWIDTH - 105, 151, 120, 15, ": Click for login hours")

		TextGadget(#LABEL_GROUP, 10, 170, 110, 15, "User groups :")
		EditorGadget(#GROUPS, 10, 185, 350, 190, #PB_Editor_ReadOnly)
		SetGadgetFont(#USER, FontID(#FONT_EDITOR))
		SetGadgetFont(#GROUPS, FontID(#FONT_EDITOR))
	EndIf
EndProcedure

InitDomain()
InitImages()
LoadFont(#FONT_EDITOR, "Courier New", 8)
LoadFont(#FONT_HOURS, "Luncida Console", 10)
LoadFont(#FONT_NAME, "Luncida Console", 8, #PB_Font_Bold)

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Taille_Ecran.RECT, 0)
Largeur_Ecran = (Taille_Ecran\Right - Taille_Ecran\Left)-5
Hauteur_Ecran = (Taille_Ecran\Bottom - Taille_Ecran\top)-25
OpenWindow_WIN_GETADGROUPS(Largeur_Ecran-#_IWIDTH,Hauteur_Ecran-#_IHEIGHT)

SetWindowCallback(@WinCallback())

SetActiveGadget(#USER_LOGIN)
;http://msdn.microsoft.com/en-us/library/bb761607%28VS.85%29.aspx
SendMessage_(GadgetID(#USER_LOGIN), #EM_LIMITTEXT, 8, 0)   ;8 car max
; ou http://www.purebasic.fr/english/viewtopic.php?p=301303#p301303

;- Event loop
Repeat
	Select WaitWindowEvent()

		Case #PB_Event_ActivateWindow
			SetActiveGadget(#USER_LOGIN)
			SendMessage_(GadgetID(#USER_LOGIN),#EM_SETSEL,0,-1)

		Case #PB_Event_Gadget
			Select EventGadget()
				Case #BUTTON_OK
					ViewGroups(GetGadgetText(#USER_LOGIN))
			EndSelect

		Case #PB_Event_CloseWindow
			Select EventWindow()
				Case #WIN_GETADGROUPS
					CloseWindow(#WIN_GETADGROUPS)
					Break
			EndSelect

		Case #WM_KEYDOWN
			Select EventwParam()

				Case #VK_RETURN
					ViewGroups(GetGadgetText(#USER_LOGIN))

			EndSelect

	EndSelect
ForEver
Pref file "DOMController.prefs" example:

Code: Select all

[Entity]
EntityOrder=Domain3,Domain1,Domain2,Domain5

[Domain1]
Domain = 10.0.0.2
Name = BOULDER Company
Remark = Primary server

[Domain2]
Domain = 10.0.0.3
Name = BOULDER Company
Remark = Secondary server

[Domain3]
Domain = RORSCHACH
Name = PSYCHO Company
Remark = ^^

[Domain4]
Domain = DC_VS230
Name = SAGITTARUS
Remark = 

[Domain5]
Domain = DC_VS232
Name = PISCES
Remark = 

[Domain6]
Domain = DC_VS234
Name = CAPRICA
Remark = Cylon control
>>> Edit for PB5.11 <<<
Last edited by flaith on Mon Apr 22, 2013 1:42 pm, edited 6 times in total.
“Fear is a reaction. Courage is a decision.” - WC
Amundo
Enthusiast
Enthusiast
Posts: 200
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: Get Windows Active Directory Groups

Post by Amundo »

Thanks flaith, this will come in VEEEERRRRRYY handy!

For anyone that hasn't needed to yet (including me!), to compile you need to enable 2 Compiler Constants in the Compiler Options (#PB_Editor_CompileCount and #PB_Editor_BuildCount).
Win10, PB6.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get Windows Active Directory Groups

Post by Kwai chang caine »

Thanks FLAITH for sharing 8)
I have not full understand the utility, but that's works fine :oops:
Amundo wrote:For anyone that hasn't needed to yet (including me!), to compile you need to enable 2 Compiler Constants in the Compiler Options (#PB_Editor_CompileCount and #PB_Editor_BuildCount).
Thanks for the tips :wink:
Me too, i have error message and not dare ask to my friend FLAITH why the code never works with KCC :oops:
ImageThe happiness is a road...
Not a destination
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

Amundo wrote:Thanks flaith, this will come in VEEEERRRRRYY handy!
you're welcome :D
Amundo wrote:For anyone that hasn't needed to yet (including me!), to compile you need to enable 2 Compiler Constants in the Compiler Options (#PB_Editor_CompileCount and #PB_Editor_BuildCount).
:oops: forgot to mention it, thanks for having noticed it :mrgreen:
Kwaï chang caïne wrote:Thanks FLAITH for sharing 8)
you're welcome too :D
“Fear is a reaction. Courage is a decision.” - WC
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Re: Get Windows Active Directory Groups

Post by Xombie »

Yes - thanks! AD is something I was going to need some help in the near future and this will come in very handy.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

Glad to know that, thanks xombie :D
“Fear is a reaction. Courage is a decision.” - WC
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Get Windows Active Directory Groups

Post by SFSxOI »

Is this missing a structure or something?
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

SFSxOI wrote:Is this missing a structure or something?
"Missing a structure" : i don't think so, what do you mean ?
“Fear is a reaction. Courage is a decision.” - WC
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Get Windows Active Directory Groups

Post by SFSxOI »

For this "LongonHours.a[21]" no matter what i do, I keep getting "Structure not found: a."
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

Good point SFSxOI :D

forgot to say that i'm using PB 4.40 :

Code: Select all

Ascii        .a      1 Byte                0 to +255
Char        .c      1 Byte (ascii)      0 to +255
for PB 4.31 better use ".c" without unicode :wink:
“Fear is a reaction. Courage is a decision.” - WC
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Get Windows Active Directory Groups

Post by SFSxOI »

Ahhhh ok then thats it. I'm not using the beta. I wish people would post which version things are for, it drove me nuts. I kept thinking "flaith said it works so it works, the problem must be on my end then. What the heck am I doing wrong?"

Thanks for your reply :)
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Get Windows Active Directory Groups

Post by OldSkoolGamer »

How can this be used to search more than 1 domain.

If I am on the domain oldman I can only find users on that domain, how would you go about searching all domains on the network ?
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

Hi,

in this code i'm using 2 domains (line 103) :

Code: Select all

; *** IMPORTANT ***
; Change value by your own servername
#First_DOMAIN           = "PDC_01"
#First_DOMAIN_NAME      = "Primary"
#Second_DOMAIN          = "PDC_02"
#Second_DOMAIN_NAME     = "Secondary"
and i check if i find the user in the first domain, or i check to the second domain if i didn't find the user and i jump to the 'cont:' label (line 334)

hope it helps a little :wink:
“Fear is a reaction. Courage is a decision.” - WC
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Get Windows Active Directory Groups

Post by OldSkoolGamer »

Yes, I got that part, I even added 2 more domains since we have 4 where I work, but I cannot view any user from other domains except the one I am logged onto. Something I am overlooking maybe ?

added these two:

#Third_DOMAIN = "TN.get"
#Third_DOMAIN_NAME = "Opryland"
#Fourth_DOMAIN = "TX.get"
#Fourth_DOMAIN_NAME = "Texan"

also adjusted this:

If domainesuivant = #True
domainesuivant = #False
ProcedureReturn Str(GetInfo)
ElseIf domainesuivant = #True
PokeS(*dcname, #Second_DOMAIN, -1, #PB_Unicode)
dcname = PeekS(*dcname, -1, #PB_Unicode)
Goto cont:
ElseIf domainesuivant = #True
PokeS(*dcname, #Third_DOMAIN, -1, #PB_Unicode)
dcname = PeekS(*dcname, -1, #PB_Unicode)
Goto cont:
ElseIf domainesuivant = #True
PokeS(*dcname, #Fourth_DOMAIN, -1, #PB_Unicode)
dcname = PeekS(*dcname, -1, #PB_Unicode)
Goto cont:
EndIf


But it fails out if I try to view any others except the TN.get domain which I am logged onto, possibly a cross-domain issue ?
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Get Windows Active Directory Groups

Post by flaith »

I will try tomorrow at work and find another way to search a user :wink:
“Fear is a reaction. Courage is a decision.” - WC
Post Reply