I am making an application using c#.net. It contains a filesystem minifilter driver also. I want to install and uninstall this driver programmatically using c# .net. Normally i can install this using the .INF file (by right click + press install).but I want to install this programmatically. There is an SDK function InstallHinfSection() for installing the .inf driver . I am looking for a .net equivalent for this function.
Regards
Navaneeth
The user can then right click on the inf file shown in the list and view the content in the richedit box on the right bottom of the screen or open it in Notepad by right clicking on the particular entry in listview. Once the user is sure that the inf can be uninstalled, they can right click and select Uninstall.
Right-Click InstallIn Windows Explorer, select and hold (or right-click) the INF file name. A shortcut menu will appear. Select Install.
inf drivers that were displaying the inf file you selected does not support this method of installation error by using Device Manager. This might work if the INF driver doesn't have the required install parameters to run conventionally (Right-click > Install) but it's configured to be installed through Device Manager.
Try something like this:
using System.Runtime.InteropServices;
[DllImport("Setupapi.dll", EntryPoint="InstallHinfSection", CallingConvention=CallingConvention.StdCall)]
public static extern void InstallHinfSection(
[In] IntPtr hwnd,
[In] IntPtr ModuleHandle,
[In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer,
int nCmdShow);
Then to call it:
InstallHinfSection(IntPtr.Zero, IntPtr.Zero, "my path", 0);
I generated most of this signature using the P/Invoke Signature Generator.
The full details of this method and its parameters are on MSDN. According to MSDN the first parameter can be null, the second one must be null, and the last parameter must be 0. You only have to pass in the string parameter.
This simple code worked for me
private void driverInstall()
{
var process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c C:\\Windows\\System32\\InfDefaultInstall.exe " + driverPath; // where driverPath is path of .inf file
process.Start();
process.WaitForExit();
process.Dispose();
MessageBox.Show(@"Driver has been installed");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With