Get the Windows OS Login name using Ruby?

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

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 :slight_smile:

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

That said I think there is s nice builtin way of accessing windows
.sub!(" s “,” a ")

On Fri, Apr 17, 2009 at 10:08 AM, Mmcolli00 Mom
[email protected]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=Windows+logged+on&cginame=namazu.rb&submit=Search&dbname=ruby-talk&max=50&whence=0

“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)

On Friday 17 April 2009 11:12:27 Kyle S. 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 :slight_smile:

ENV[‘USERNAME’]

Was that so hard? Or does that not work on Windows?

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

Wow, funny enouhg, I don’t recall using ENV before. Nice.
And I just verified on a windows box, yea that does work.