From: Craig Moran Date: 2005-04-26T04:33:47+09:00 Subject: Re: Get the Current Domain Name in Windows Try this for a simple solution: require 'win32ole' p ENV['USERDOMAIN'] These extra ENV arguments should work as well. To cite the source, I Googled and found them in this blog: http://blogs.officezealot.com/charles/archive/2004/12/10/3574.aspx ALLUSERSPROFILE APPDATA AVENGINE CLIENTNAME CommonProgramFiles COMPUTERNAME ComSpec FP_NO_HOST_CHECK HOMEDRIVE HOMEPATH INCLUDE INOCULAN LIB LOGONSERVER NUMBER_OF_PROCESSORS OS Path PATHEXT PROCESSOR_ARCHITECTURE PROCESSOR_IDENTIFIER PROCESSOR_LEVEL PROCESSOR_REVISION ProgramFiles SESSIONNAME SystemDrive SystemRoot TEMP TMP USERDOMAIN USERNAME USERPROFILE VS71COMNTOOLS WecVersionForRosebud.FF0 windir On 4/25/05, Brian Takita wrote: > 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. > > Here is a reference to the function I am trying to call: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netwkstausergetinfo.asp > > Here is a reference to the struct where I am trying to extract the data > from: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/wksta_user_info_1_str.asp > > Here is my code with the results in the header: > > # username: > # logon_domain: > # oth_domains: > # logon_server: > > require 'dl/win32' > > getUserNameInfo = Win32API.new('Netapi32.dll', 'NetWkstaUserGetInfo', > %w{p l P}, 'i') > bufferFree = Win32API.new('Netapi32.dll', 'NetApiBufferFree', %w{p}, > 'l') > > reserved = "\0" * 4 > buf = " " * 4 * 255 > > begin > getUserNameInfo.call(reserved, 1, buf) > username, logon_domain, oth_domains, logon_server = buf.unpack('AAAA') > puts 'username: ' + username > puts 'logon_domain: ' + logon_domain > puts 'oth_domains: ' + oth_domains > puts 'logon_server: ' + logon_server > ensure > bufferFree.call(buf) > end > > Thank you, > Brian Takita > >