Ruby with WMI but that is not the problem.

H

happy-jack

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

[Start 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}

[/End Code]


This does

[Start 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}

[/End Code]

Can someone shed some light on this???
 
D

Daniel Berger

happy-jack said:
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

[Start Code]
require 'win32ole'

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

Try STDIN.gets
cpuName.chomp

Try 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}

[/End Code]

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top