The easiest way to do this is to run the same command as the "Install" item does on the right-click menu of an INF file in Windows Explorer
1) Get the Install command from the registr
2) Add your file name as the command argumen
3) Run the comman
Note that some INF files need to write an entry to the "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce" registry key which requires the user running the INF file to have write permission on that key. However, if you will always be running the INF file as an Administrator then you shouldn't need to worry about this
The following function that will do what you need..
Public Function InstallInfFile(ByVal strFileName As String) As Boolea
Dim strClassName As String = "
Dim strInstallCommand As String = "
Dim blnInstallationSuccess As Boolean = Fals
Dim objSubKey As RegistryKe
strFileName = strFileName.Tri
'Do a basic check to ensure that the specified file is an INF file and actually exist
If (strFileName.Length >= 4) AndAlso (strFileName.Substring(strFileName.Length - 4, 4).ToUpper = ".INF") AndAlso File.Exists(strFileName) The
'Get the command from the regitry that is used to install INF file
objSubKey = Registry.LocalMachine.OpenSubKey("Software\Classes\.inf"
If Not IsNothing(objSubKey) The
strClassName = objSubKey.GetValue("").Tri
objSubKey.Close(
If (strClassName.Length > 0) The
objSubKey = Registry.LocalMachine.OpenSubKey("Software\Classes\" & strClassName & "\shell\Install\command"
If Not IsNothing(objSubKey) The
strInstallCommand = objSubKey.GetValue("").Tri
objSubKey.Close(
End I
End I
End I
'Check that the expected argument placeholder exists at the end of the strin
If (strInstallCommand.Length > 3) AndAlso (strInstallCommand.Substring(strInstallCommand.Length - 3, 3) = " %1") The
'Replace the argument placeholder with the name of the INF fil
strInstallCommand = strInstallCommand.Substring(0, strInstallCommand.Length - 2) & strFileNam
'Install the INF fil
blnInstallationSuccess = (Shell(strInstallCommand, AppWinStyle.Hide, True) = 0
End I
End I
Return blnInstallationSucces
End Functio
Hope this is of some help
Gary