Forum: Ruby get the Windows OS Login name using Ruby?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cf63da956b6ba955687a2f2f262928cb?d=identicon&s=25 Mmcolli00 Mom (mmcolli00)
on 2009-04-17 18:08
Do you know if there is a way to get the Windows OS Login name using
Ruby? I can do this with VB but haven't found a way to do this in Ruby.

Thanks
MC
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2009-04-17 18:13
(Received via mailing list)
May not be pretty, but you can always do

username=%x[echo %USERNAME%].strip


A decent sized list of windows environmental variables is here:
http://vlaurie.com/computers2/Articles/environment.htm

That said I think there _is_ s nice builtin way of accessing windows
environmental variables in ruby, but it's been so long I'd probably
just shell out using %x :)
B14575f0ca69f10938fdd67e7156e0e1?d=identicon&s=25 Craig Demyanovich (Guest)
on 2009-04-17 18:17
(Received via mailing list)
I don't know of a way. You could look at the Ruby on Windows blog [
http://rubyonwindows.blogspot.com/ ] or search Google while waiting for
others to reply.

Regards,
Craig
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2009-04-17 18:17
(Received via mailing list)
> That said I think there _is_ s nice builtin way of accessing windows
.sub!(" s "," a ")
9d4960f8319664f0f7896230eebace73?d=identicon&s=25 Glen Holcomb (Guest)
on 2009-04-17 18:28
(Received via mailing list)
On Fri, Apr 17, 2009 at 10:08 AM, Mmcolli00 Mom
<mmc_collins@yahoo.com>wrote:

> Do you know if there is a way to get the Windows OS Login name using
> Ruby? I can do this with VB but haven't found a way to do this in Ruby.
>
> Thanks
> MC
> --
> Posted via http://www.ruby-forum.com/.
>
>
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb?key...
--
"Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying."

-Greg Graffin (Bad Religion)
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (djberg96)
on 2009-04-17 19:04
(Received via mailing list)
Mmcolli00 Mom wrote:
> Do you know if there is a way to get the Windows OS Login name using
> Ruby? I can do this with VB but haven't found a way to do this in Ruby.

require 'etc'
p Etc.getlogin

# OR

gem install sys-admin
require 'sys/admin'
p Sys::Admin.get_login

Regards,

Dan
1bc63d01bd3fcccc36fb030a62039352?d=identicon&s=25 David Masover (Guest)
on 2009-04-17 20:04
(Received via mailing list)
On Friday 17 April 2009 11:12:27 Kyle Schmitt wrote:
> May not be pretty, but you can always do
>
> username=%x[echo %USERNAME%].strip
[...]
> That said I think there _is_ s nice builtin way of accessing windows
> environmental variables in ruby, but it's been so long I'd probably
> just shell out using %x :)

ENV['USERNAME']

Was that so hard? Or does that not work on Windows?
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2009-04-17 20:16
(Received via mailing list)
Wow, funny enouhg, I don't recall using ENV before.  Nice.
And I just verified on a windows box, yea that does work.
This topic is locked and can not be replied to.