Solved

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

Posted on 2011-09-14
2
1,454 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virus On motherboard 6 85
auto script to stop bitdefender to scan my external drives 6 68
SSD mSata 250GB 37 72
IIS components 2 15
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…

840 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