Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ruby WMI but that is not the problem 1

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hey I am new to ruby and I do Windows administration. I have been playing with wmi and ruby, having a problem. This is not a problem with th wmi part but when I use get. I am asking for a computer name and then putting that information into the script. This does not work
Code:
require 'win32ole'

puts "what is the computer name that you want to use??? "
cpuName = gets
cpuName.chomp

mgmt = WIN32OLE.connect("winmgmts:\\\\#{cpuName}")
mgmt.InstancesOf("Win32_ComputerSystem") .each{ |item| puts item.name + "\n" + item.Manufacturer + " - " + item.Model}
mgmt.InstancesOf("Win32_SystemEnclosure").each{ |dev| puts dev.SerialNumber}

This does
Code:
require 'win32ole'

cpuName = 'aname'

mgmt = WIN32OLE.connect("winmgmts:\\\\#{cpuName}")
mgmt.InstancesOf("Win32_ComputerSystem") .each{ |item| puts item.name + "\n" + item.Manufacturer + " - " + item.Model}
mgmt.InstancesOf("Win32_SystemEnclosure").each{ |dev| puts dev.SerialNumber}

Can someone shed some light on this???

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Try:
Code:
puts "what is the computer name that you want to use??? "
cpuName = gets
cpuName.chomp!
Or:
Code:
puts "what is the computer name that you want to use??? "
cpu = gets
cpuName = cpu.chomp

The .chomp method returns the chomped bit, but it has to be assigned to a variable to be used. .chomp! will return the original variable in chomped state.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top