Le 16 avr. 08 à 15:09, Alexander Cohen a écrit :

Whats the best way in cocoa to get a list of users on a machine for 10.4 and up?

thx

AC

The most reliable way to do it is to use Directory Services.
There is no official Obj-C DS API (The DSObjcWrapper is part of darwin and is open sources but it's a private framework) and the C API is fairly complex.

But, POSIX call uses Directory Service API under the hood, so using the BSD API is probably the way to go:

#include <sys/types.h>
#include <pwd.h>

int main () {
  struct passwd *p;

  while ((p = getpwent())) {
    // Note: p->pw_uid is declared as an unsigned int,
// but Darwin uses it as an signed value (nobody has id -2), so you have to cast it
    if ((int32_t)p->pw_uid >= 500) {
      printf ("id %d = '%s'\n", p->pw_uid, p->pw_name);
    } else {
      printf ("(system) - id %d = '%s'\n", p->pw_uid, p->pw_name);
    }
  }

  return 0;
}

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to