Seite 1 von 1

alle zur zeit angemeldete benutzer

Verfasst: 13.07.2010 10:17
von jpd
NetWkstaUserEnum listet informationen über alle zur zeit angemeldete benutzer and der Workstation.

lauffäig ab Win 2000
getestet auf XP/Win7/2003

Code: Alles auswählen

; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
; coded by jpd, july 2010
; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
; http://msdn.microsoft.com/en-us/library/aa370669(VS.85).aspx
; ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
EnableExplicit 

#NERR_SUCCESS=0
#MAX_PREFERRED_LENGTH  = -1
#ERROR_MORE_DATA = 234

Structure WKSTA_USER_INFO_1
  wkui1_username.l
  wkui1_logon_domain.l
  wkui1_oth_domains.l
  wkui1_logon_server.l
EndStructure

Prototype NetWkstaUserEnum(dwServer.p-unicode, level.l, bufptr.l, prefmaxlen.l, dwEntriesread.l, dwTotalentries.l, dwResumehandle.l)

Global NetWkstaUserEnum.NetWkstaUserEnum

Procedure LoadNETAPI() 
  Protected Result 

  Result = OpenLibrary(#PB_Any, "netapi32.dll") 
  If Result 
    
    NetWkstaUserEnum=GetFunction(Result, "NetWkstaUserEnum")
    
    If NetWkstaUserEnum = 0 
      CloseLibrary(Result) 
      Result = 0 
    EndIf      
  EndIf 
  
  ProcedureReturn Result 
  
EndProcedure 


Define   initlib.l 
Define   bufptr.l
Define   dwServer.l
Define   dwEntriesread.l
Define   dwTotalentries.l
Define   dwResumehandle.l
Define   nStatus.l
Define   nStructSize.l
Define   cnt.l
Define   bServer.s
Define   wui1.WKSTA_USER_INFO_1

initlib=LoadNETAPI()
If initlib
  
  InitNetwork()
  bServer = "\\" +Hostname()
  nStatus=#ERROR_MORE_DATA
  While nStatus  = #ERROR_MORE_DATA
    nStatus=0
    nStatus = NetWkstaUserEnum(bServer, 1, @bufptr, #MAX_PREFERRED_LENGTH, @dwEntriesread, @dwTotalentries, @dwResumehandle)
    Debug GetLastError_()                           
    If nStatus = #NERR_SUCCESS Or nStatus = #ERROR_MORE_DATA 
      If dwEntriesread > 0 
        nStructSize = SizeOf(WKSTA_USER_INFO_1)
        For cnt = 0 To dwEntriesread - 1
          CopyMemory (bufptr + (nStructSize * cnt),@wui1,nStructSize); nStructSize
          Debug "User Name: "+PeekS(wui1\wkui1_username,-1,#PB_Unicode)
          Debug "Logon Domain: "+PeekS(wui1\wkui1_logon_domain,-1,#PB_Unicode)
          Debug "Logon Server: "+PeekS(wui1\wkui1_logon_server,-1,#PB_Unicode)
          Debug "Other Domain: "+PeekS(wui1\wkui1_oth_domains,-1,#PB_Unicode)
          Debug "----------------------"
        Next
      EndIf
        
    Else 
      Debug nStatus  
    EndIf
  Wend 
  NetApiBufferFree_(bufptr)
  CloseLibrary(initlib)
EndIf 

Re: alle zur zeit angemeldete benutzer

Verfasst: 13.07.2010 10:35
von Rings
das geht aber nicht unter Ubunto 10.4 ,
warum eigentlich nicht ?

Re: alle zur zeit angemeldete benutzer

Verfasst: 13.07.2010 10:58
von jpd
Danke für den Hinweis,

habe mein erster post angepasst.

Ciao
jpd

Re: alle zur zeit angemeldete benutzer

Verfasst: 13.07.2010 11:41
von NicTheQuick
Da gerade die Rede von Ubuntu war. Es gibt ja den Konsolenbefehl 'users', der alle angemeldeten Benutzer auflistet. Und von dieser Art Befehle gibt es ja auch noch eine ganze Menge mehr. Soll ich jetzt immer die Ausgabe eines solchen Programms auslesen und verwerten oder gibt es da auch schicke APIs, die ich einfach verwenden kann? Ich bin nämlich scheinbar zu blöd diese ausfindig zu machen.

Re: alle zur zeit angemeldete benutzer

Verfasst: 14.07.2010 13:24
von jpd
Hallo NicTheQuick,

für mich ist das "neuland", habe den API call "getutent" gefunden..
die structure utmp ist nicht ausführlich umgesetzt, aber ist erstmal ein anfang. :)

getestet unter Ubuntu 9.x

Ciao
jpd

P.S. Run "man utmp" and "man getutent" for more information...

Code: Alles auswählen

; /* The `struct utmp' type, describing entries in the utmp file.  GNU version.



#UT_LINESIZE	 = 32
#UT_NAMESIZE =	32
#UT_HOSTSIZE	 = 256

;
Structure  utmp
; /* The Structure describing an entry in the user accounting database.  */
  ut_type.l ;short int ut_type;		/* Type of login.  */
  ut_pid.l;pid_t ut_pid;			/* Process ID of login process.  */
  ut_line.c[#UT_LINESIZE];	/* Devicename.  */ char
  ut_id.c[4];char ut_id[4];		/* Inittab ID.  */
  ut_user.c[#UT_NAMESIZE];char ut_user[#UT_NAMESIZE];	/* Username.  */
  ut_host.c[#UT_HOSTSIZE];char ut_host[UT_HOSTSIZE];	/* Hostname for remote login.  */
  ut_exit.l;struct exit_status ut_exit;	/* Exit status of a process marked  As DEAD_PROCESS.  */
  ; /* The ut_session And ut_tv fields must be the same size when compiled
  ut_session.l;long int ut_session;		/* Session ID, used for windowing.  */
  timeval.l ;struct timeval ut_tv;		/* Time entry was made.  */
  ut_addr_v6.l;[4]int32_t ut_addr_v6[4];	/* Internet address of remote host.  */
  __unused.c[20];		/* Reserved for future use.  */
EndStructure


;/* Values For the `ut_type' field of a `struct utmp'.  */
#EMPTY	=	0	;/* No valid user accounting information.  */

#RUN_LVL = 1	;/* The system's runlevel.  */
#BOOT_TIME =	2	;/* Time of system boot.  */
#NEW_TIME = 3	;/* Time after system clock changed.  */
#OLD_TIME	= 4	;/* Time when system clock changed.  */

#INIT_PROCESS =	5	;/* Process spawned by the init process.  */
#LOGIN_PROCESS	= 6	;/* Session leader of a logged in user.  */
#USER_PROCESS  =	7	;/* Normal process.  */
#DEAD_PROCESS = 8	;/* Terminated process.  */

#ACCOUNTING =	9

;/* Old Linux name For the EMPTY type.  */
#UT_UNKNOWN =	#EMPTY


; /* Tell the user that we have a modern system With UT_HOST, UT_PID,
;    UT_TYPE, UT_ID And UT_TV fields.  */
#_HAVE_UT_TYPE =	1
#_HAVE_UT_PID =	1
#_HAVE_UT_ID =	1
#_HAVE_UT_TV = 1
#_HAVE_UT_HOST =	1

;-start

ut.utmp
Repeat 
  *user=getutent_()
  ;While *user <>0
  If Not *user=0
    
    CopyMemory(*user, @ut.utmp,SizeOf(utmp))
    
    Debug "UserName: "+PeekS(@ut\ut_user,#UT_NAMESIZE)
    Debug "Process ID of login process: "+Str(PeekL(@ut\ut_pid))
    Debug  "Type of login:" +Str(PeekL(@ut\ut_type))
    Debug "Session ID:  " +Str(PeekL(@ut\ut_session))
    Debug "Inittab ID: "+PeekS(@ut\ut_id,4)
    Debug "Hostname for remote login: "+PeekS(@ut\ut_host,#UT_HOSTSIZE)
    Debug "Devicename: " + PeekS(@ut\ut_line,#UT_LINESIZE)
    Debug "Exit: "+Str(PeekL(@ut\ut_exit))
    Debug "-------------------------------------------------"
    
  EndIf
  
Until *user=0