Solved

VB Script to verify video driver version and then update if it's not correct

Posted on 2011-09-14
2
1,411 Views
Last Modified: 2013-11-08
Hello,

I am trying to create a vbscript that would check the video driver version and then update the driver if it is not the correct version. I have a few different machine models and various display adapters. It will need to verify the hardware and driver version then install the correct driver unattended. Below is the vbs that I started which will identify the video driver version and model. Where I am stuck is how to get the script to use the info to verify and then carry out the install. I also need to ensure the event is captured in the event viewer which I believe is almost complete but not sure if a failure is recorded. Can someone please help with reviewing this to see what I am missing. I can't seem to figure out how to get it to verify then install from a network location. Also how to handle other models? Do I just cut and paste the process and change the else command?

Sorry - please bear with me - but I am pretty new to vbscript and I still have ALOT to learn as you will see..Honestly, I am truly amazed I even got this far on my own. I am open to suggestions. Many Thanks!



On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_VideoController")

For Each objItem in colItems
    For Each strCapability in objItem.AcceleratorCapabilities
        Wscript.Echo "Accelerator Capability: " & strCapability
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Driver Date: " & objItem.DriverDate
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "INF Filename: " & objItem.InfFilename
    Wscript.Echo "Installed Display Drivers: " & _
        objItem.InstalledDisplayDrivers
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
  WScript.Echo "Manufacturer: " & objItem.Manufacturer
  WScript.Echo "Model: " & objItem.Model
Next

Const EVENT_SUCCESS = 0

Set objShell = Wscript.CreateObject("Wscript.Shell")

objShell.LogEvent EVENT_SUCCESS, _
    "Video Driver Update Successfully Installed by IT."
   
Next

If driver version Is Not 8.15.10.2321 And the model =nvidia Then install (\\server\data\files\drivers\nvidia\setup.msi /qn)
Else End
0
Comment
Question by:Willing2Learn_More
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
Hi, give this a try, in which you need to change the array at the top.

Note that you must know the command to use for silent installation.

Read this bit about the array:
' In the array, specify each driver in four components, with the
' full computer model, part or all of the driver name,
' the desired driver version, and the command to run the install
arrDrivers = Array( _
      "Latitude D620", "nvidia", "8.15.10.2321", "cmd.exe \\server\share\nvidia\driver.exe -silent", _
      "Optiplex 990", "ati", "11.8", "msiexec.exe -i \\server\share\ati\driver.msi -qn -noreboot"

Regards,

Rob.
On Error Resume Next

' In the array, specify each driver in four components, with the
' full computer model, part or all of the driver name,
' the desired driver version, and the command to run the install
arrDrivers = Array( _
	"Latitude D620", "nvidia", "8.15.10.2321", "cmd.exe \\server\share\nvidia\driver.exe -silent", _
	"Optiplex 990", "ati", "11.8", "msiexec.exe -i \\server\share\ati\driver.msi -qn -noreboot"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_VideoController")

For Each objItem in colItems
    For Each strCapability in objItem.AcceleratorCapabilities
        Wscript.Echo "Accelerator Capability: " & strCapability
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Driver Date: " & objItem.DriverDate
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "INF Filename: " & objItem.InfFilename
    Wscript.Echo "Installed Display Drivers: " & objItem.InstalledDisplayDrivers
    WScript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID

    strDriverVersion = objItem.DriverVersion
    strName = objItem.Name
Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
	WScript.Echo "Manufacturer: " & objItem.Manufacturer
	WScript.Echo "Model: " & objItem.Model
	
	strModel = objItem.Model
Next

Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1

Set objShell = CreateObject("Wscript.Shell")

strCommand = ""
For i = 0 To UBound(arrDrivers) - 3 Step 4
	If LCase(strModel) = LCase(arrDrivers(i)) Then
		If InStr(LCase(strName), LCase(arrDrivers(i + 1)) > 0 Then
			If strDriverVersion <> arrDrivers(i + 2) Then
				strCommand = arrDrivers(i + 3)
				Exit For
			End If
		End If
	End If
Next

If strCommand <> "" Then
	intReturn = objShell.Run strCommand, 0, True
	If intReturn = 0 Then
		objShell.LogEvent EVENT_SUCCESS, "Video Driver Update Successfully Installed by IT."
	Else
		objShell.LogEvent EVENT_ERROR, "Video Driver Updated Failed with Return Code " & intReturn & "."
	End If
End If

Open in new window

0
 

Author Closing Comment

by:Willing2Learn_More
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As you can read I recycle all my old hardware and the time has come that my power supply of 200 Watt cannot provide enough power for my backup server. I have lots of Compaq power supply's laying around, so I figured to use one of these PSU's. I t…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now