B
Brian Takita
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/d...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/d...-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
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/d...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/d...-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