Skip to content

Instantly share code, notes, and snippets.

@dougm
Created June 3, 2010 00:24
Show Gist options
  • Save dougm/423239 to your computer and use it in GitHub Desktop.
Save dougm/423239 to your computer and use it in GitHub Desktop.
#unsed in Chef::Util::Windows::NetUse; may come in handy later.
require 'chef/util/windows'
class Chef::Util::Windows::NetUse < Chef::Util::Windows
def get_all
list = []
handle = 0.chr * PTR_SIZE
rc = ERROR_MORE_DATA
while rc == ERROR_MORE_DATA
ptr = 0.chr * PTR_SIZE
nread = 0.chr * PTR_SIZE
total = 0.chr * PTR_SIZE
rc = NetUseEnum.call(nil, 2, ptr, -1, nread, total, handle)
if (rc == NERR_Success) || (rc == ERROR_MORE_DATA)
ptr = ptr.unpack('L')[0]
nread = nread.unpack('i')[0]
members = 0.chr * (nread * SIZEOF_USE_INFO_2)
memcpy(members, ptr, members.size)
nread.times do |i|
offset = i * SIZEOF_USE_INFO_2
use = use_info_2_unpack(members[offset,SIZEOF_USE_INFO_2])
list << use
end
NetApiBufferFree(ptr)
else
raise ArgumentError, get_last_error(rc)
end
end
list
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment