how do I find the name of the current user?

Discussion in 'Ruby' started by Sam Roberts, Apr 3, 2005.

  1. Sam Roberts

    Sam Roberts Guest

    I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be best
    on unix, is there a windowsy equivalent?

    Thanks,
    Sam
     
    Sam Roberts, Apr 3, 2005
    #1
    1. Advertising

  2. Sam Roberts

    Csaba Henk Guest

    Csaba Henk, Apr 3, 2005
    #2
    1. Advertising

  3. Sam Roberts

    Sam Roberts Guest

    Quoting csaba@phony_for_avoiding_spam.org, on Sun, Apr 03, 2005 at 11:54:43AM +0900:
    > On 2005-04-03, Sam Roberts <> wrote:
    > > I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be best
    > > on unix, is there a windowsy equivalent?

    >
    > Would this help you?
    > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/135205


    It looks great, but I don't want to use it until its in the stdlib. Its
    a little more than I want to get the name of the current user.

    But, I'll remember, I might need it in the future.

    Thanks
    Sam
     
    Sam Roberts, Apr 3, 2005
    #3
  4. Sam Roberts

    Alan Chen Guest

    On Win XP and 2000 I think you can depend on ENV['USERNAME'], on older
    windows versions I'm not sure...

    - alan
     
    Alan Chen, Apr 3, 2005
    #4
  5. Sam Roberts wrote:
    > Quoting csaba@phony_for_avoiding_spam.org, on Sun, Apr 03, 2005 at

    11:54:43AM +0900:
    > > On 2005-04-03, Sam Roberts <> wrote:
    > > > I'm thinking Etc.getlogin followed by Etc.getpwnam.gecos might be

    best
    > > > on unix, is there a windowsy equivalent?

    > >
    > > Would this help you?
    > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/135205

    >
    > It looks great, but I don't want to use it until its in the stdlib.

    Its
    > a little more than I want to get the name of the current user.
    >
    > But, I'll remember, I might need it in the future.
    >


    I don't know how portable this is, but:

    irb(main):001:0> ENV["USER"]
    => "cmills"

    -Charlie
     
    Charles Mills, Apr 3, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Newton
    Replies:
    0
    Views:
    2,967
    Mike Newton
    Jul 23, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,679
    Steve C. Orr [MVP, MCSD]
    Jul 23, 2004
  3. nalbayo
    Replies:
    2
    Views:
    5,595
    Bruce Barker
    Nov 11, 2005
  4. Herb

    How to find Current User Name

    Herb, Jul 23, 2007, in forum: ASP .Net Security
    Replies:
    5
    Views:
    434
    Dominick Baier
    Jul 23, 2007
  5. Matthew Heidemann
    Replies:
    14
    Views:
    269
    eT Ma
    Mar 22, 2011
Loading...

Share This Page