# Ruby Windows user information and Active Directory querying

**URL:** <https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108>\
**Category:** Ruby\
**Created:** [July 11, 2007, 3:55pm UTC](https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108 "2007-07-11T15:55:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fufufu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/91b2a8/32.png) [@fufufu](https://www.ruby-forum.com/u/fufufu)\
**Post date:** [July 11, 2007, 3:55pm UTC](https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108/1 "2007-07-11T15:55:54Z")

</div>

Hi,

Does someone have a few guidelines for the following:

- Get the information about the user currently logged in (at least  
username would be good),
- Use the above information to query the Active Directory (can net/  
ldap or ruby/ldap be used for this successfully?) for other info,  
specifically group membership?

I am on WinXP, but any guidelines might help (e.g. getting username on  
\*nix or querying LDAP on Mac). An important thing is that, from the  
examples I have seen (e.g. a good one with Rails on top -  
[http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap](http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap)), you  
need a few things to query AD - the login name, the password (a no-no  
for storing within the script), base dn and other stuff.

All of these can change if you change the access place, so a good way  
would be to fetch everything at runtime. I know that all of these can  
be found in the information Windows can provide for the current user,  
because various vbs scripts can do this (e.g.  
[http://www.computerperformance.co.uk/ezine/ezine138.htm](http://www.computerperformance.co.uk/ezine/ezine138.htm)). Can  
something similar be done in Ruby easily (as tons of other stuff can)?

---

<div class="post-metadata">

**Author:** ![fufufu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/91b2a8/32.png) [@fufufu](https://www.ruby-forum.com/u/fufufu)\
**Post date:** [July 11, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108/2 "2007-07-11T15:57:55Z")

</div>

On 10 jul, 16:45, fu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \*nix or querying LDAP on Mac). An important thing is that, from the  
> examples I have seen (e.g. a good one with Rails on top -[http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap](http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap)), you  
> need a few things to query AD - the login name, the password (a no-no  
> for storing within the script), base dn and other stuff.
> 
> All of these can change if you change the access place, so a good way  
> would be to fetch everything at runtime. I know that all of these can  
> be found in the information Windows can provide for the current user,  
> because various vbs scripts can do this (e.g.[http://www.computerperformance.co.uk/ezine/ezine138.htm](http://www.computerperformance.co.uk/ezine/ezine138.htm)). Can  
> something similar be done in Ruby easily (as tons of other stuff can)?  
> Hi,

With Apache(and a proxy directive) you will be able to retrieve the  
remote user from the client.  
(normally the format is like this DOMAIN/USERNAME).

The following section

‘Reading REMOTE\_USER from mongrel through proxy’ on  
[http://mongrel.rubyforge.org/docs/apache.html](http://mongrel.rubyforge.org/docs/apache.html) explains this.

Regards,  
Stijn Van Vreckem

---

<div class="post-metadata">

**Author:** ![fufufu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/91b2a8/32.png) [@fufufu](https://www.ruby-forum.com/u/fufufu)\
**Post date:** [July 11, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108/3 "2007-07-11T16:02:56Z")

</div>

Stijn, thanks for the info. However, I am not talking about Web  
applications here (although I am not excluding them also - if there is  
a solution in a Web-application-form which solves what I need, I’d be  
glad to look at it). The thing I need is a console-like application  
that queries AD and gets the groups for the current user. The  
problems: how to get the current user (i.e. not having the user to  
type his username), how to authenticate to AD (i.e. without the user  
needing to enter his password) and how to access the info from AD.  
It’s not the login (authentication) that I need, just a query.  
Basically, a Ruby version of \*nix ‘groups’ program, just for Windows.

---

<div class="post-metadata">

**Author:** ![fufufu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/91b2a8/32.png) [@fufufu](https://www.ruby-forum.com/u/fufufu)\
**Post date:** [July 11, 2007, 4:38pm UTC](https://www.ruby-forum.com/t/ruby-windows-user-information-and-active-directory-querying/109108/4 "2007-07-11T16:38:59Z")

</div>

fu wrote:

> Does someone have a few guidelines for the following:
> 
> - Get the information about the user currently logged in (at least  
> username would be good),

Perhaps the ENV object might help here:

ENV[‘USERNAME’]

returns the Windows user’s name or Windows login

> **[Making Use of Ruby's ENV Object](http://rubyonwindows.blogspot.com/2007/06/making-use-of-rubys-env-object.html)**
>
> Ruby provides the ENV object for easy access to a variety of environment variables. ENV is not actually a hash, but you access individual va...

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform
