[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Get the Current Domain Name in Windows

Berger, Daniel

4/25/2005 6:43:00 PM

> -----Original Message-----
> From: Brian Takita [mailto:brian.takita@gmail.com]
> Sent: Monday, April 25, 2005 11:29 AM
> To: ruby-talk ML
> Subject: Get the Current Domain Name in Windows
>
>
> Hello,
>
> I am trying to find out the domain name for the current user.
> This is my first endeavor into dl/win32 and I am having no
> luck getting the data.

<snip>

Here's an alternative approach using OLE + WMI:

require "win32ole"
require "socket"

host = ARGV[0] || Socket.gethostname

cs = "winmgmts:{impersonationLevel=impersonate}!"
cs << "//#{host}/root/cimv2"
wmi = WIN32OLE.connect(cs)

wmi.InstancesOf("Win32_ComputerSystem").each{ |obj|
p obj.domain
p obj.username
}

See
http://msdn.microsoft.com/library/default.asp?url=/library/en-...
wmi/win32_computersystem.asp for more info.

Regards,

Dan



1 Answer

Brian Takita

4/25/2005 7:28:00 PM

0

Thank you Dan,

This works wonderfully.