Get current active desktop console user

Hi,
I am googling for some time trying to find a way to determine UserID
of user using the physical console. I am after a command that can be
run from terminal, ssh, cron.
"who" shows all users logged in with Fast user switching,
all of them on 'console' but I see no way to figure out who is
the one using the desktop that time.
Many hits point to CGSession, but so far I was not able find the options
to get the ID of current console user. It is certain that this binary has
access to the value, because when trying -switchToUserID it can respond with:
Unable to Fast User Switch: User must be the current console user or root.
Is there any way to find out current console user? Would appreciate also
a pointer to some library I can call from C and printf the value.
Thanks in advance.
Andrej

Hi,
Your post was 100% to the point. Thanks a million. I was hoping there would be a binary in the system already to provide the info needed, so this forum appeared the most appropriate. So far I've never compiled my C program on a Mac but with the info from published documents it was a snap:
(how to paste code samples to this forum??)
mac40:timemgmt amk$ cat loguser.c
#include <stdio.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <CoreFoundation/CFString.h>
http://developer.apple.com/library/mac/#qa/qa2001/qa1133.html
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPMultip leUsers/Concepts/FastUserSwitching.html#//apple_ref/doc/uid/20002209-BAJDIHBJ
static CFStringRef CopyCurrentConsoleUsername(SCDynamicStoreRef store)
// Returns the name of the current console user, or NULL if there is
// none. store may be NULL, in which case a transient dynamic store
// session is used.
CFStringRef result;
result = SCDynamicStoreCopyConsoleUser(store, NULL, NULL);
// If the current console user is "loginwindow", treat that as equivalent
// to none.
if ( (result != NULL) && CFEqual(result, CFSTR("loginwindow")) ) {
CFRelease(result);
result = NULL;
return result;
main(int ac, char*av)
CFStringRef cf;
const char * s;
if ( ( cf = CopyCurrentConsoleUsername ( NULL ) ) != NULL )
if ( ( s = CFStringGetCStringPtr ( cf, CFStringGetFastestEncoding ( cf ) ) ) != NULL )
printf ( "%s\n", s );
exit ( 0 );
perror ( "Get current console user" );
exit ( 1 );
mac40:timemgmt amk$ cc -o loguser loguser.c -framework CoreFoundation -framework SystemConfiguration
mac40:timemgmt amk$ who | grep console
ivka console Nov 25 07:11
eyetv console Nov 22 12:31
mac40:timemgmt amk$ ./loguser
eyetv
mac40:timemgmt amk$
BTW, I am trying to implement a kind of distributed parental control with global time limits over multiple computers.
Thanks!

Similar Messages

  • How to get the activity of a user?

    Hi Experts,
    How can we get the activity of a user i.e. Which transaction a particular user has gone or some activity log on a particular date? Any table, FM or Tcode. I have already checked the STAD and SM20 transactions. Some authorization problem. So anything except these Tcodes would be helpful. Thanks in advance.
    Regards,
    Prashant.

    >
    santhosh kumar wrote:
    > Hi,
    >
    > I guess if it is not updated or traced under STAD means, i.e. related to authorization failures etc.. kind of stuff will be saved at runtime only in the SAP memory.
    >
    > As it is stored in the buffer, can not be traced in any of the transaction.
    > You should request the user to save and send the screen shot of the SU53 of the user whenever he gets some authorization issue.
    >
    > Based on that, by looking into the SUIM transaction, it can be known whether he is authorized or not, which roles have been assigned etc.. kind of details.
    >
    > Regards,
    > Santhosh.
    Hi Santosh,
    Actually I am doing a root cause analysis for which I need to know whether a particular user has used a particular TCode. I guess the STAD will display only the current data, is there a TCode to display historical data related to user accessing a particular data. Note: I don't have basis authorization.
    Regards,
    Prashant

  • How do i get current active or selected page item's  reference

    Hi all,
    How do i get current active or selected page item's  reference .
    Please help me

    You can implement a selection suite for your need, this selection suite will be placed into the kLayoutSuiteBoss.
    In this selection suite place a method to give you the UIDRef of the selected pageitem, which you can get by using the method "GetUIDList" of the "ILayoutTarget" interface.
    Manan Joshi
    - Efficient InDesign Solutions -
    MetaDesign Solutions
    http://metadesignsolutions.com/services/indesign-development.php

  • How to get current active tab (Detailitem)

    Hello,
    i have searched everywhere and still can't find a solution for such simple task. I want to get the current active Detailitem value (af:showDetailitem) from a panelTabbed (using java class)
    Working on Jdeveloper 11.1.2.4.0,
    can you help me please?

    Was hoping something more abstract solution, like getting the current instances of active tabs and find out what is the active at that running moment. Ah well, its 2013 and still disappointed by Java.
    Thanks a lot for your help Subramanina, i used something similar to your suggestion:
    1) i have change my main function, and set it to accept a string (that will be the tab's id) for my purpose
    2) on each tab, i add a disclosure event function. Inside that, i just simply save the tab's id on a private variable. So when ever
    i want the current active tab id, i just get that variable's value.
    3) PartialTrigger the panel with tabs
    Almost the same solution with yours, just mine is less professional since i lost you there

  • Get current logged in Windows user name

    Hi
    Is it possible to retrieve the current logged in Windows user name into a text field automatically?
    Thank you in advance for the help.

    Hi,
    This is a security issue and you will need a javascript file in the Acrobat folder. This will contain a trusted function allowing access to the login name.
    Here is a thread that looked at this:
    http://forums.adobe.com/message/2198084#2198084
    However read to the end, because if you are Reader Enabling the form (at least through Acrobat) then you may run into problems.
    Good luck,
    Niall

  • How to get Current Log in BO user name in data access driver

    In universe, to get the current log in user is via @Variable('BOUSER').
    Right now, I need to be able to get the user name in the data access driver. I am writing a customized data access driver because we need to patch some where clause on the the query generated by the universe based on the logged-in user info. I only think of using end_sql parameter or adding an universe level filter to patch the @Variable('BOUSER') to the query, which would not work if user want to use customized query.
    Can anyone tell me how to get currentBO user name from connection server ? or how @Variable('BOUSER') is translated into the logged-in user name in the universe?

    Shweta,
    The link you provided was the Auditor guide for BO 6.x, I'm not sure it that is going to help Karen or not.
    Karen,
    There is function called connection
    (usage:  =connection([Query Name]), where [Query Name]
    denotes the name of the tab for the query under Edit Query)
    Here is some of the output from connection:
    4;ODBC18;MS SQL Server 2000166; VERSION=7; USER=xxxxx;
    PASSWORD=; DBTYPE=Relational; DATABASE=xxx_xxxx;
    ODBC_USER=xxxxxx; ODBC_PASSWORD=; BO_DSN=xxxx_xxxx;
    BO_DRV_CONNECT_MODE=0; 224; VERSION=6; Name=xxxxx; Shared=4;
    LoginTimeout=600; Timeout=600; Pool Time=60; Array Fetch Size=10;
    Array Bind Size=5; RecommendedLenTransfert=1000; Password_Encryption=x;
    AliasTable=; MeasureDimension=; Hint=; ConnectInit=; ArrayFetch=1;
    I'm not sure if this info helps out either, being that connection provides info on a post-processing basis and it sounds like you need to get out ahead of the SQL generation.  The @variable('bouser') would seem like the place to be, however, in allowing custom SQL to take place you loose the bouser due to an individual could customize the SQL to the point that it gets unwantingly yanked out.  The end_sql might be your answer...
    Thanks,
    John

  • Get current PCD path from user context

    Hi expert,
    Anyone has an idea how to get the pcd path of WDJ ? from user context ?
    Thanks for your quick reponse.
    Kr,
    Ben.J.

    Hi Ben,
    I am not quite sure what your use case is here.
    However, have a look at this link:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/b4/adbf40b87e0366e10000000a1550b0/frameset.htm
    If it is for navigational purposes, you can use the WDPortalNavigationService.
    Have a look at http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/2f72d990-0201-0010-85b0-8d626287dd4d
    - SM

  • Which table stores SM04 (currently active users) data?

    HI all,
    what is the table which stores the SM04 currently active users data in sap?
    plzzzzzzzzz help me..
    Thanks all in advance ,
    Malti

    SM04 uses a kernel call to get the active user data, not table is involved:
    Get the list of logged on users
        CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
            ID 'TAB' FIELD USR_TABL-SYS.
    Markus

  • Get current directory(without user.dir)!!!!

    Dudes,
    need help badly... i need to get the current directory of the jar file where it gets launched from. Since the launching takes place from an html file, the system property "user.dir" does not get set to the current directory. Both the html as well as the jar file is in the same location.
    so in short, i need to get the current dir without using the user.dir that i can later set it explicitly thru my program(to the current dir)

    "Search the CLASSPATH for the first occurence of your jar file... but FFS only do it once, and save the result"
    Cud ya elaborate that statement.
    Also, the reason i wanna know is this : my jar file references all the images that it uses, thru a relative path(./a/b/c.....). So wen i simply double click the jar file, the relative path("./") gets replaced with the current workin directory(from user.dir) and fetching of images works perfectly. But if it is launched via html, the user.dir does not get set to the current working dirctory and as a result the jar file looks for its images in the default location which is the desktop. so it doesnt work
    Now that the context is clear, is there a way out???? or is there any way in which i can set the user.dir from the html itself(maybe by using javascript or somethin??)

  • How can I get that which one is currently activated window

    I created a frame. The user may be minimize that frame and he may use some other window like internet explorer or Notepad or something else. Then I want to know that which window is the currently activated window. Is it possible. Please help me.

    you can use Javascript functions/varibles.
    In any page you can insert a special form like this:
    <form name="myNameWindow">
    <input type="hidden" name="myName" value="Ivan_pag01">
    </form>
    and in the other reading that value.
    Obviusly you have to save a reference in a variable of the other window.
    This is possible only if:
    1) other page is in the same browser window but in an other frame
    2) you have generated the other page via an "window.open" function (or your page is generated from it via that function)
    -- Ivan

  • How to get the number of current active external modes?

    hi all,
    I need to get the number of currently active external modes. This can be done by calling function THUSRINFO. But this only works propperly, if you are logged on only once. If you are logged on more than one time then the function returns several entries in the parameter USR_TABLE. The entries mainly differ in the first parameter TID (type UTID, INT4) "terminal-identification" but how can I know which is the valid one for my current session. Functions TERMINAL_ID_GET, SPH_TERMINAL_IDENTIFY and SPH_TERMINAL_ID_GET dont work.
    Or is there another way to get the number of active external sessions?
    Thanks in advance,
    Michael

    Hi,
    tables: usr02, usr41.
    data: OPCODE_MODE_COUNT(1) TYPE X VALUE 3,
          modes like sy-index,
          u_MODES LIKE MODES.
    select * from usr02.
      select * from usr41 where BNAME = usr02-bname.
        CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE_MODE_COUNT
          ID 'TID' FIELD usr41-TERMID
          ID 'MODES' FIELD MODES.
        IF SY-SUBRC = 0.
          u_MODES = u_MODES + MODES.
        ENDIF.
      endselect.
      if sy-subrc = 0.
        write:/ usr02-bname, u_MODES.
      endif.
      clear u_modes.
    endselect.

  • How to get current logged-in user name in data access driver or in universe

    In universe, to get the current log in user is via @Variable('BOUSER').
    Right now, I need to be able to get the user name in the data access driver. I am writing a customized data access driver because we need to patch some where clause on the the query generated by the universe based on the logged-in user info. I only think of using end_sql parameter or adding an universe level filter to patch the @Variable('BOUSER') to the query, which would not work if user want to use customized query.
    Can anyone tell me how to get currentBO user name from connection server ? or how @Variable('BOUSER') is translated into the logged-in user name in the universe?

    I do not know your EJB Service. But you should pass the credentials of the current logged on portal user to your service. That's not by default I think.
    I had a similar problem with CAF developed webservices. I had to turn on permission checks in my web service and passed the credentials via logon ticket.
    Regards, Bernd

  • How to get the specific name of the workset which is currently selected by the user in sap portal 7.0

    Dear Expert,
    I have one requirement like to read the selected workset name in portal by the current user.I have read two documents regarding how to retrieve the PCD contents (iViews, Pages, Worksets and Roles) and its properties like Created by, Changed by, Last changed by and others using PCD API.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/6112ecb7-0a01-0010-ef90-941c70c9e401?overridelayout=true
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/508baf88-9335-2d10-efa6-c6ad61e5fc4b?quicklink=index&overridelayout=true
    But I am not able to understand how to get the specific name of the workset which is currently selected by the user.Can you please help me.
    I am using portal 7.0.
    Thanks & Regards,
    Patralekha

    Hi Expert,
    I found that we can use Interface INavigationHelperService to read Portal Role selected by user at runtime from http://scn.sap.com/thread/52194
    But this class is available in SAP NetWeaver 7.30 Enterprise Portal .
    But in SAP NetWeaver 7.0 Enterprise Portal that interface is not available.
    INavigationService is available there.
    But didn't get any proper discussion on this interface for the same requirement.
    Can you please help me.
    Thanks & Regards,
    Patralekha

  • Getting the active role of an user in a trigger

    Hello forum!!
    I've been searching to find out if and how I can get the active role of an user when programming a trigger.
    Unfortunately I did not succeed in finding some information about this. Is it possible? If yes, how?
    Thanks for any hint regarding this topic.
    Sebastian

    Thanks for the answers. This helped a lot but it does not seem to work within my triggers.
    CREATE OR REPLACE TRIGGER InscriptionsInsert BEFORE INSERT OR UPDATE ON Inscriptions
      FOR EACH ROW
      DECLARE
        active_role VARCHAR2(11);
      BEGIN
        SELECT role INTO active_role FROM session_roles WHERE role != 'CONNECT';
        IF :new.ni < 1000 AND active_role = 'ind_service' THEN
          RAISE(ABORT, 'le service individuelle ne peut pas faire les inscriptions pour des sportifs');   
        END IF;
        IF :new.i >= 1000 AND active_role = 'eq_service' THEN
          RAISE(ABORT, 'le service equipe ne peut pas faire les inscriptions pour des equipes');   
        END IF;
      END;
    CREATE OR REPLACE TRIGGER ResultatsInsert BEFORE INSERT OR UPDATE ON Resultats
      FOR EACH ROW
      DECLARE
        forme VARCHAR2(12);
        active_role VARCHAR2(11);
      BEGIN
        SELECT forme INTO forme FROM Epreuves WHERE nEpreuve = :new.nEpreuve;
        SELECT role INTO active_role FROM session_roles WHERE role != 'CONNECT';
        IF forme = 'individuelle' AND active_role = 'eq_service'
          RAISE(ABORT, 'le service equipe ne peut pas enregistre des resultats pour des sportifs');
        END IF;
        IF forme = 'equipe' AND active_role = 'ind_service'
          RAISE(ABORT, 'le service individuelle ne peut pas enregistre des resultats pour des equipes');
        END IF;
      END; 

  • How to get the name of the city and state of the current location of the user

    Hi all
             i need to get the name of the city and state (full address) of the current location of the user.
    need help.

    The best way to do this is to put the monitor name as a property bag in the script and pass that to your event details. Otherwise, we're looking at querying the database each time the monitor generates an event, and this is overhead that is really not
    necessary. The other option, which is just even worse in terms of performance, is to use powershell to query the SDK for the monitor name. Both of these options are not going to be a good solution, because now you need to implement action accounts that can
    either query the database or the sdk.
    Jonathan Almquist | SCOMskills, LLC (http://scomskills.com)

Maybe you are looking for