• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the User/Owner of another process
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the User/Owner of another process


  • Subject: Re: Getting the User/Owner of another process
  • From: David Remahl <email@hidden>
  • Date: Tue, 30 Sep 2003 17:51:25 +0200

On 30 sep 2003, at 16.51, John Farmer wrote:

I need to be able to get the User/Owner of another process, like Finder. I
need to do this because I need to get the user name of the person currently
logged in. Now before you berate me, I did try to use NSUserName(),
NSFullUserName() functions.

There seems to be a very subtle bug in these functions. These functions were
unsuccessful because I am trying to get the user name of the person currently
logged in, in the Startup Item I am using, but contrary to the documentation
for these two functions, they do not get the User Name of the user currently
logged in they get the User Name of WHOEVER HAS OWNERSHIP OF THE APPLICATIONS
PROCESS (for Startup Items this seems always to be Root).

This is the correct behaviour. Remember, you are now working on a multi user system. Several users ca nbe logged in at the same time, graphically or with a shell. Especially with Fast User Switching in Panther, you cannot make any assumptions about the "logged in user", except for what NSUserName() gives you, since there may be several. There is no guarantee that the Finder session you find, is the one associated with the user who is currently occupying the keyboard.

As we have discussed before, there seems to be no API for finding the current person "active" in Fast User Switching.

So I need to someway get the name of the person logged in, in a Startup Item
so I can setup the last preferences for the app and driver I am writing. The
only way I have thought of to do this, is to be able to get the User Name of
the user that owns the Finder process (which always seems to have the current
logged in user as the owner of that process... see the Process Viewer). Does
anyone have any suggestions on how to do this, or how to otherwise get the
current users login name in a Startup Item?

It shouldn't be very difficult to find the user of the Finder. The easiest solution may be to use the 'ps' tool with an NSTask, and parse the output. The other alternative is to use the same method that ps uses to get at the information. This would involve the system call "sysctl()". You can find out more about that on "man 3 sysctl", or by reading the ps source. I also think this sample code may be of help:

<http://developer.apple.com/qa/qa2001/qa1123.html>

Then again, I don't think this is the solution you want. You will probably want to restore these settings on some other level in your system, perhaps when the user starts the frontend for your driver (I don't know what kind of driver you're working on, so it's difficult to guess.)

/ Rgds, David Remahl
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Getting the User/Owner of another process (From: "John Farmer" <email@hidden>)

  • Prev by Date: Re: Getting the User/Owner of another process
  • Next by Date: Re: Call CFM shlb from Cocoa
  • Previous by thread: Re: Getting the User/Owner of another process
  • Next by thread: Re: Getting the User/Owner of another process
  • Index(es):
    • Date
    • Thread