get the Windows OS Login name using Ruby?

M

Mmcolli00 Mom

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
 
K

Kyle Schmitt

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 :)
 
K

Kyle Schmitt

That said I think there _is_ s nice builtin way of accessing windows
sub!(" s "," a ")
 
G

Glen Holcomb

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
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb?key=3DWindows+logged+on&cgin=
ame=3Dnamazu.rb&submit=3DSearch&dbname=3Druby-talk&max=3D50&whence=3D0
--=20
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can=92t hear a word you=92re saying."

-Greg Graffin (Bad Religion)
 
D

Daniel Berger

Mmcolli00 said:
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
 
D

David Masover

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?
 
K

Kyle Schmitt

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top