alx*_*x9r 5 windows powershell cmdlets driver
注意:对于这个问题,当我提到“Windows 驱动程序”时,我指的是 .inf 和相关文件,否则可以通过右键单击 .inf 并在 Windows 资源管理器中单击“安装”来安装这些文件。我的意思不是任何可能安装驱动程序的 setup.exe 风格的可执行文件。
存在以下情况:
Get-WindowsDriver -online
- 一个 Powershell Cmdlet,输出正在运行的系统的当前安装的驱动程序Add-WindowsDriver
- 将驱动程序添加到脱机映像的 Powershell Cmdlet 。相应的Remove-WindowsDriver
可用于从离线映像中删除驱动程序。dpinst.exe
- 一个命令行工具,可用于将驱动程序安装到正在运行的系统。 dpinst.exe /u
可以与卸载驱动程序一起使用。但是,我还没有找到支持在正在运行的系统上安装和卸载驱动程序的相应 Powershell Cmdlet 。我确信我可以包含dpinst.exe
在一些 powershell 中,但是如果存在更多 Powershell 原生方法,我想避免映射命令行参数和解析输出。
是否存在可以在运行的系统上安装和卸载 Windows 驱动程序的 Powershell Cmdlet?是否有其他不涉及使用 Powershell 安装和卸载 Windows 驱动程序的方法dpinst.exe
?
不仅没有用于此的 PowerShell cmdlet,而且似乎在 .Net 框架中甚至没有托管代码来执行此操作(以下内容基本上是将该答案转换为 PowerShell)。
幸运的是,.Net 框架可以通过平台调用(p/invoke)调用 windows API,PowerShell 也可以这样做。
链接的答案显示了如何在 C# 中做到这一点。为此,我们将使用在该答案中生成的相同签名,并将其与Add-Type
cmdlet(参见示例 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)
Run Code Online (Sandbox Code Playgroud)
有关参数(特别是字符串格式)的详细信息,请参阅InstallHinfSection的MSDN 文档。
归档时间: |
|
查看次数: |
19880 次 |
最近记录: |