windows - 是否有安装和删除 Windows 驱动程序的 Powershell cmdlet?

标签 windows powershell driver powershell-cmdlet

注意:对于这个问题,当我提到“Windows 驱动程序”时,我指的是 .inf 和相关文件,否则可以通过右键单击 .inf 并单击 Windows 资源管理器中的“安装”来安装这些文件。我指的不是任何一种可能会安装驱动程序的 setup.exe 样式的可执行文件。


存在以下内容:

但是,我还没有找到支持在正在运行的系统 上安装和卸载驱动程序的相应 Powershell Cmdlet。我确定我可以将 dpinst.exe 包装在一些 powershell 中,但如果存在更多 Powershell 本地方法,我想避免映射命令行参数和解析输出。

是否存在可在运行的系统上安装和卸载 Windows 驱动程序的 Powershell Cmdlet?有没有其他方法可以使用不涉及 dpinst.exe 的 Powershell 安装和卸载 Windows 驱动程序?

最佳答案

不仅没有用于此的 PowerShell cmdlet,我 t seems there isn't even managed code to do it within the .Net framework (接下来基本上是将该答案翻译成 PowerShell)。

幸运的是,.Net 框架可以通过平台调用 (p/invoke) 调用 Windows API,PowerShell 也可以这样做。

链接的答案显示了如何在 C# 中执行此操作。为此,我们将使用在该答案中生成的相同签名,并将其与 Add-Type cmdlet (see example 5) 一起使用使其可用于您的脚本。

$signature = @"
[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);
"@
$Win32Functions = Add-Type -MemberDefinition $signature -UsingNamespace System.Runtime.InteropServices -Name Win32SInstallHinfSection -Namespace Win32Functions -PassThru 

$Win32Functions::InstallHinfSection([IntPtr]::Zero, [IntPtr]::Zero, "<section> <mode> <path>", 0)

参见 MSDN documentation for InstallHinfSection有关参数的详细信息(特别是字符串格式)。

关于windows - 是否有安装和删除 Windows 驱动程序的 Powershell cmdlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32320013/

相关文章:

c++ - 将菜单资源添加到对话框

c++ - 如何在所有平台上使用 C++ 程序显示重音字符?

java - 没有找到合适的驱动程序调用 getConnection

linux - 如何创建将系统调用转发到我的程序的 "fake filesystem"?

powershell - 嵌套循环抽象

linux - 特定 USB 设备的识别发生在 Linux 源代码的哪个位置?

c - 如何在 Windows 内核驱动程序中编译 OPENSSL(RSA、DSA、HMAC)?

c++ - 如何居中QMainWindow?

Powershell Core + Pester - 将测试与 src 分开

bash - 在 Ubuntu/Bash 和 Windows/Powershell 之间生成具有不同结果的 SHA1 签名