Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
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.
; /* 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