Solved

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

Posted on 2011-09-14
2
1,443 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
ID: 36535290
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
ID: 36546452
Thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When experiencing some peculiar problem with the functioning of your PC, how many times has it happened that you look for a solution and even google can’t help? It could be that you are one of the only few people on earth who ma…
Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

773 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