Private Sub Version2()
Dim Cnt As Integer
Dim RegKey As RegistryKey = Registry.LocalMachine.CreateSubKey( _
"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2")
Dim SubKeys() As String = RegKey.GetSubKeyNames()
Dim DriverAdd As String
If SubKeys.Length > 0 Then
For Cnt = 0 To SubKeys.Length - 1
DriverAdd = (SubKeys(Cnt))
' Declares the True\False switch of whether or not the product header has
' been written in each of the variable files.
Dim dDriverName As Boolean
' Sets dDriverName to True
dDriverName = False
' Attempts to open the database, if not it returns an error
Try
' Declares myConnection as the database connection
myConnection = Me.cnDatabase()
' Opens the databse
myConnection.Open()
Catch ex As Exception
'Display Error Message
MessageBox.Show(ex.Message, "Database Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Stop)
End
Application.Exit()
End Try
' Runs the data reader to gather all of the information from the DataSet (dsMain)
rdrVersion2 = Me.cmdGetValues.ExecuteReader()
' Performs the data read gainst the dataset from the database
With rdrVersion2
' Performs While statement while there are still records to be read
While .Read
' Reads data from the DataSet (dsMain) for the 5 columns in the DataSet
dataRow = Me.dsMain.tbl_PrintID_PrintName.NewRow
' Data: String name of the printer driver itself
dataRow(4) = .GetString(4)
' Checks to see if the driver string from the registry matches a driver in the database
If DriverAdd = dataRow(4) Then
' If dDriverName is True
If Not dDriverName Then
' Sets bHeader to True
dDriverName = True
' Write the driver name to the checked list box
lbDriversVer2.Items.Add(DriverAdd)
End If
End If
End While
End With
Try
' Close the database
myConnection.Close()
Catch ex As Exception
'Display Error Message
MessageBox.Show(ex.Message)
End Try
Next Cnt
End If
End Sub