2

WMI: VBscript to show the model of a computer

Posted February 4th, 2010 in model and tagged , , , , , by dirk adamsky

Let’s continue the with another short WMI script.
This script shows the model of your computer
Default computer is the local machine.
When the dot is replaced by another machine name the script works against that machine.
With some additions the script can be used for a simple inventory of the pc’s in your network.

There are some conditions that must be met:

  1. the script must be run with administrative credentials
  2. the firewall of the remote machine needs the following ports opened for WMI: TCP 135, TCP 4168 and
    UDP 9256

Follow the next steps to make and run the script (admin rights needed):

  • open your favorite text editor (mine is notepad++)
  • copy and paste the script into the editor (delete the line numbers)
  • save the script (for example c:tempmodel.vbs)
  • open a command prompt
  • go to “c:temp”
  • give “cscript model.vbs” (without quotes) and enter

The script:

' Name : model.vbs
' Description : script to show the model of a computer
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 04-02-2010
' Level : beginner

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Computersystem")
For Each Item In colItems
	Wscript.Echo strComputer & " " & Item.Model
Next
Set objMemory = Nothing
Set objWMIService = Nothing

As said earlier: when you have questions/problems please give a reply.

Best regards,

Dirk Adamsky – Deludi BV


Related Posts:
  • VBscript: vbscript to enumerate the printers of Active Directory users and write the results to a file
  • Active Directory and WMI: VBscript to enumerate the ntfs rights of a given UNC path and a given level of subfolders
  • Active Directory and WMI: VBscript to enumerate the system uptime of all servers in Active Directory V2

  • 2 Responses so far.

    1. Damion says:

      Thanks for sharing this. It worked perfectly for me. Would you be willing to help me a little further? I am trying to detect the model number in WinPE and after finding the model then copy the drivers from the network to the local hard drive based on the model number. I have been able to detect the model using “wmic csproduct get name” but doing something with it is another story. I have tried using WMI … IF string1=string2 commands but no luck. Any help would be fantastic.

      thanks

    2. dirk adamsky says:

      Hi Damion,

      Maybe there is another solution for what you want to accomplish.
      I think you are working on an unattended install or something like that.
      I have good experiences with Nlite (http://www.nliteos.com/).
      With Nlite you can add drivers (plug-and-play and/or textmode) to your source image.
      During installation of the OS they will be found (with the device id) and installed.

      Best regards,

      Dirk Adamsky

    Leave a Reply