且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#.net以编程方式安装/卸载.inf驱动程序

更新时间:2022-12-01 16:31:59

尝试如下操作:

 使用系统.Runtime.InteropServices; 

[DllImport( Setupapi.dll,EntryPoint = InstallHinfSection,CallingConvention = CallingConvention.StdCall)]
公共静态外部无效InstallHinfSection(
[In] IntPtr hwnd,
[In] IntPtr ModuleHandle,
[In,MarshalAs(UnmanagedType.LPWStr)]字符串CmdLineBuffer,
int nCmdShow);

然后称呼它:

  InstallHinfSection(IntPtr.Zero,IntPtr.Zero,我的路径,0); 

我使用 P /调用签名生成器



此方法及其参数的完整详细信息位于 MSDN 。根据MSDN,第一个参数可以为null,第二个必须为null,最后一个参数必须为0。只需传递字符串参数。 / p>

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

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.