2
votes

I found this script that gives you the username in Windows, but I get the following error, this is not about the username but about the missing lib, I need the lib dl/win32 also for a couple other scripts. How to fix this?

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- dl/win32 (LoadError)

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

puts get_user_name
2

2 Answers

2
votes

I'm unsure what "dl/win32" is. I have used the Win32API gem. Using it instead of dl/win32 made your script work for me:

require 'Win32API'
0
votes

My best guess is you have to run

gem install dl