Get the Current Domain Name in Windows


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

wmi/win32_computersystem.asp for more info.




-----Original Message-----
From: Brian Takita []
Sent: Monday, April 25, 2005 11:29 AM
To: ruby-talk ML
Subject: Get the Current Domain Name in Windows


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.

Thank you Dan,

This works wonderfully.