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

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
Willing2Learn_MoreAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
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
 
Willing2Learn_MoreAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.