bvillados
Posts: 12
Score: 0 Joined: 8/14/2002 Status: offline
|
I'm somewhat of a beginner when it comes to writing VB scripts. My task is to create a VB script that'll run during the building of a PC using OSD. The script will read the model of the PC from WMI, and then runs through a series of IF statements - one for each model of PC we support. Depending on the model name, it will copy a series of driver files for that model from a network source to the PC's C: drive. I've already written the script, and it has been working great for quite some time. Then I was given an HP e-PC 42 and am tasked to add this model to OSD. But in the process of building this PC, the drivers were never being copied to the C: drive. I've discovered that for some reason the script never ran the copy statement because the IF statement being used was never ringing true. To troubleshoot WMI and the script, I've written a small VB script that performs a simple test to see if the model name is being read correctly. I obtained the model name using WMI Explorer, exported the results to a text file, and then used debug to make darn sure that there are no control characters or other non-ASCII characters in the WMI queried model name. Here's the script: Dim objWMI : Set objWMI = GetObject("winmgmts:")
Dim colSettingsComp : Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")
Dim objComputer, strModel
For Each objComputer in colSettings
strModel = objComputer.Model
Next
If strModel = "e-pc 42" Then
wscript.echo "i am an e-pc 42"
End ifThe problem I'm having is that, in the If statement (3rd line from the bottom), the statement is never true. Therefore, that "I am an e-pc 42" statement never pops up. I tried this script on other PCs of different models (of course, changing the string in the quotations to match the model of the PC), and they all work. It's just that for some strange reason the script has a problem with "e-pc 42" where it is never equal to the model generated by WMI. Again, on an ASCII level the model name from WMI and this string matches. Is there some special about this string "e-pc 42" that makes the VB script choke? Thanks!
|