使用C#.net以编程方式安装/卸载.inf驱动程序 [英] install/uninstall an .inf driver programmatically using C# .net

查看:791
本文介绍了使用C#.net以编程方式安装/卸载.inf驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#.net制作应用程序。它还包含文件系统微型过滤器驱动程序。我想使用c#.net以编程方式安装和卸载此驱动程序。通常,我可以使用.INF文件安装此文件(通过右键单击并按install)。但是我想以编程方式进行安装。有一个SDK函数InstallHinfSection()用于安装.inf驱动程序。我正在寻找一个等效于.net的函数。



问候



Navaneeth

解决方案

尝试如下操作:

 使用系统.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.

这篇关于使用C#.net以编程方式安装/卸载.inf驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆