I need get the name of the domain user in Windows.
Here are the ways by which I tried to get a name, but they all return the domain name:
1.
...
ENV['username'] # or ENV['USERNAME'] or ENV['userid']
...
2.
...
require 'etc'
puts Etc.getlogin
...
3.
...
require 'dl/win32'
def get_user_name
api = Win32API.new(
'advapi32.dll',
'GetUserName',
'PP',
'i'
)
buf = "\0" * 512
len = [512].pack('L')
api.call(buf,len)
buf[0..(len.unpack('L')[0])]
end
...
4.
This way return string "system":
...
require 'win32ole'
network=WIN32OLE.new("Wscript.Network")
puts network.username
...
How can I get username or pair domain\username?