This is probably enough for the list to look over. What do you guys
think -- idiomatic Ruby or not? Also, if I'm doing anything that's not
safe (should I close 'mgmt' or 'net' somehow) please let me know.
Thanks again for the feedback.
require 'win32ole'
# Get running process names, ids and paths (if present)
mgmt = WIN32OLE.connect("winmgmts:\\\\.")
mgmt.InstancesOf("win32_process").each do |p|
puts p.name.to_s + "\t" +
p.processid.to_s + "\t" +
p.executablepath.to_s
end
Note that you can use print with several arguments - that way you
don't need to create the complete string in mem and then write it (not
a performance problem in this small piece of code but I may be in
other circumstances). You can do
print p.name, "\t",
p.processid, "\t",
p.executablepath, "\n"
There are tons of other ways including printf etc.
puts
# Get the IP, Mac Address and Gateway of Active Network Interfaces.
net = WIN32OLE.connect("winmgmts:\\\\.")
net.InstancesOf("win32_networkadapterconfiguration").each do |i|
if i.ipenabled == false
#puts "Interface Disabled"
else
puts i.ipaddress
puts i.defaultipgateway
puts i.macaddress
end
end
This looks pretty neat. Some minor remarks: don't compare booleans -
just use them. In your case
if i.ipenabled
puts i.ipaddress, i.defaultgateway, i.macaddress
else
puts "disabled"
end
Or the other way round if you prefer:
unless i.ipenabled
puts "disabled"
else
...
end
Kind regards
robert
···
2006/3/6, rtilley <rtilley@vt.edu>:
--
Have a look: Robert K. | Flickr