Mega Code Archive

 
Categories / Delphi / Files
 

Installing an INF file inside your application

Title: Installing an INF file inside your application? Question: How to install an INF file inside Delphi Applications? Answer: INF files(INFormation file) are a text files used by Microsoft Windows Setup API for installing device drivers for hardware components. An INF file consists of a set of named sections, each containing one or more line items. The normal method to install a .inf file is to right mouse click on it and select Install from its menu. However, sometimes you may want to install an inf file inside software application. To do this, you can try following function. Declare ShellApi in the uses clause function Install_INF(const Path: string; WHandle: HWND): Boolean; var HINSTANCE: HINST; // A handle to the application instance begin HINSTANCE := ShellExecute(WHandle, PChar('open'), PChar('rundll32.exe'), PChar('SetupApi,InstallHinfSection DefaultInstall 132 ' + Path), nil, SW_HIDE); Result := HINSTANCE 32; end; Sample call: procedure TForm1.Button1Click(Sender: TObject); begin {Normally, IE.inf file has been using to repair Internet Explorer} if Install_INF('C:\WINDOWS\INF\IE.INF', 0) = False then Exit; end;