myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


WMI - VB scripting help needed

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> VB Script >> WMI - VB scripting help needed Page: [1]
Login
Message << Older Topic   Newer Topic >>
WMI - VB scripting help needed - 7/29/2008 9:27:12 PM   
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 if
The 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!
Post #: 1
RE: WMI - VB scripting help needed - 7/30/2008 10:32:32 AM  1 votes
akaplan


Posts: 179
Score: 21
Joined: 4/22/2003
From: North Carolina
Status: offline
Try

If lcase(strModel) = "e-pc 42" Then
wscript.echo "i am an e-pc 42"
End if

or
if instr(lcase(strModel), "e-pc 42") > 0 then
wscript.echo "i am an e-pc 42"
End if





(in reply to bvillados)
Post #: 2
RE: WMI - VB scripting help needed - 7/30/2008 2:47:25 PM  1 votes
rbennett806


Posts: 825
Score: 13
Joined: 6/14/2006
Status: offline
I do something similar during my OSD imaging as well. So for what it's worth, here's two snippets of code that might show you another (maybe easier) way to do it...

Sub SetModelInfo
' Attempts to obtain the computer model information.
Set objWMI = GetObject("winmgmts:")
Set objResults = objWMI.InstancesOf("Win32_ComputerSystemProduct")
For each objInstance in objResults
   If not IsNull(objInstance.Name) then
       strModel = Trim(objInstance.Name)
   End If
Next
If strModel = "" Then
   strModel = "UNKNOWN"
End If
End Sub


Sub CopyNetworkData
' Attempts to copy the Model specific items to the local machine.
If objFSO.FolderExists ("\\FQDNpathToServer\SharedFolder\FolderName") Then
   Set strModelFolders = objFSO.GetFolder("\\FQDNpathToServer\SharedFolder\FolderName\").Subfolders
   For Each Subfolder in strModelFolders
       re.pattern = strModel
       If (re.test (Subfolder)) Then
           objFSO.CopyFolder (Subfolder), (SystemDrive & "\LocalFolderName\"), True
       End If
   Next
End If
End Sub


And my folders out on my server match the machine model names. This way I don't have to mess with the script. I just add a new folder and I'm done...

(in reply to akaplan)
Post #: 3
RE: WMI - VB scripting help needed - 7/30/2008 2:47:42 PM   
bvillados

 

Posts: 12
Score: 0
Joined: 8/14/2002
Status: offline
This code did not work:
If lcase(strModel) = "e-pc 42" Then 
wscript.echo "i am an e-pc 42" 
End if 


This code DID WORK!!!!!!!
if instr(lcase(strModel), "e-pc 42") > 0 then 
wscript.echo "i am an e-pc 42" 
End if 
Thank you VERY MUCH!!!!!

(in reply to akaplan)
Post #: 4
RE: WMI - VB scripting help needed - 7/31/2008 11:35:42 PM   
jcondo

 

Posts: 7
Score: 0
Joined: 7/29/2008
Status: offline
Also, try ouputting the value to screen.

For Each objComputer in colSettings
 strModel = objComputer.Model
Next
If strModel = "e-pc 42" Then
wscript.echo "i am an e-pc 42"
Else
wscript.echo "UNKNOWN - I think I am a " & strModel 
End if

< Message edited by jcondo -- 7/31/2008 11:36:32 PM >

(in reply to bvillados)
Post #: 5
Page:   [1]
All Forums >> [Scripting Technologies] >> VB Script >> WMI - VB scripting help needed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.469