使用PowerShell自动安装DummyNET驱动程序

时间:2014-08-15 15:41:02

标签: windows powershell driver ipfw

tl; dr 尝试使用PowerShell /(Set | Get)-NetAdapterBinding / PnPUtil / nvspbind

自动化驱动程序/适配器绑定/适配器服务

我一直在探索在Windows Server 2012和2012 R2上的网络适配器上自动安装dummynet驱动程序。

我需要自动化这些步骤:

Pull up the properties for the Network Adapter that is used to access the Internet
Click "Install"
Select "Service" and click "Add"
Click "Have Disk" and navigate to webpagetest\dummynet
Select the ipfw+dummynet service (and click through any warnings about the driver being unsigned)

我相信我可以使用 PnPUtil 实用程序将驱动程序的INF文件添加到驱动程序存储区。

我已经探索了(Set | Get)-NetAdapterBinding powershell模块,我似乎无法让驱动程序正确注册。

以下是我通过手动方法安装后的Get-NetAdapterBinding的结果:

PS C:\Users\Administrator> Get-NetAdapterBinding public0 -DisplayName ipfw+dummynet | format-list

Caption              : MSFT_NetAdapterBindingSettingData 'Citrix PV Network Adapter #0'
Description          : ipfw+dummynet
ElementName          : unipi_ipfw
InstanceID           : {906E5591-5C6C-4D07-BB8D-BA387BA4B646}::unipi_ipfw
InterfaceDescription : Citrix PV Network Adapter #0
Name                 : public0
Source               : 1
SystemName           : ComputerName
BindName             : Ipfw
Characteristics      : 17424
ComponentClassGuid   : {4D36E974-E325-11CE-BFC1-08002BE10318}
ComponentClassName   : Filter
ComponentID          : unipi_ipfw
DisplayName          : ipfw+dummynet
Enabled              : True
PSComputerName       :
ifAlias              : public0
InterfaceAlias       : public0
ifDesc               : Citrix PV Network Adapter #0

Get-NetAdapterBinding -Name public -DisplayName ipfw+dummynet | GM    

TypeName: Microsoft.Management.Infrastructure.CimInstance#ROOT/StandardCimv2
/MSFT_NetAdapterBindingSettingData

Name                      MemberType    Definition                             
----                      ----------    ----------                             
ifAlias                   AliasProperty ifAlias = Name                         
ifDesc                    AliasProperty ifDesc = InterfaceDescription          
InterfaceAlias            AliasProperty InterfaceAlias = Name                  
Clone                     Method        System.Object ICloneable.Clone()       
Dispose                   Method        void Dispose(), void IDisposable.Dis...
Equals                    Method        bool Equals(System.Object obj)         
GetCimSessionComputerName Method        string GetCimSessionComputerName()     
GetCimSessionInstanceId   Method        guid GetCimSessionInstanceId()         
GetHashCode               Method        int GetHashCode()                      
GetObjectData             Method        void GetObjectData(System.Runtime.Se...
GetType                   Method        type GetType()                         
ToString                  Method        string ToString()                      
BindName                  Property      string BindName {get;}                 
Caption                   Property      string Caption {get;set;}              
Characteristics           Property      uint32 Characteristics {get;}          
ComponentClassGuid        Property      string ComponentClassGuid {get;}       
ComponentClassName        Property      string ComponentClassName {get;}       
ComponentID               Property      string ComponentID {get;}              
Description               Property      string Description {get;set;}          
DisplayName               Property      string DisplayName {get;}              
ElementName               Property      string ElementName {get;set;}          
Enabled                   Property      bool Enabled {get;set;}                
InstanceID                Property      string InstanceID {get;set;}           
InterfaceDescription      Property      string InterfaceDescription {get;}     
Name                      Property      string Name {get;}                     
PSComputerName            Property      string PSComputerName {get;}           
Source                    Property      uint32 Source {get;}                   
SystemName                Property      string SystemName {get;}

这是我尝试使用为该模块记录的参数设置NetAdapterBinding:

Set-NetAdapterBinding -Name public0 -Component unipi_ipfw -Enabled $True

Set-NetAdapterBinding : No matching MSFT_NetAdapterBindingSettingData objects
found by CIM query for instances of the
ROOT/StandardCimv2/MSFT_NetAdapterBindingSettingData class on the  CIM server:
SELECT * FROM MSFT_NetAdapterBindingSettingData  WHERE ((Name LIKE 'public0'))
AND ((ComponentID LIKE 'unipi[_]ipfw')). Verify query parameters and retry.
At line:1 char:1
+ Set-NetAdapterBinding -Name public0 -Component unipi_ipfw -Enabled $True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_NetAdapterBindingSettingDa
   ta:String) [Set-NetAdapterBinding], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Set-NetAdapterBindin
   g

在尝试找出执行此操作的最佳方法时,我还遇到了 nvspbind 实用程序,并尝试使用此工具添加驱动程序。不幸的是,我似乎无法将其绑定到适配器。该实用程序只是不断吐出它的使用信息。

使用PowerShell解决此问题的最佳方法是什么?

2 个答案:

答案 0 :(得分:2)

我和同事一起工作,我们找到了解决方案:

bcdedit /set TESTSIGNING ON    
Import-Certificate -FilePath C:\webpagetest\WPOFoundation.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
cd C:\webpagetest
.\mindinst.exe c:\webpagetest\agent\dummynet\64bit\netipfw.inf -i -s
Enable-NetAdapterBinding -Name private0 -DisplayName ipfw+dummynet
  1. 使用bcdedit设置 TESTSIGNING ON
  2. 然后,您必须将驱动程序提供的证书导入证书存储区,以便它是受信任的驱动程序。
  3. 然后,使用 mindinst.exe实用程序,您可以将驱动程序安装为网络服务绑定。
  4. 然后,标准 Enable-NetAdapterBinding 模块将用于启用该服务。

答案 1 :(得分:0)

您提到您能够在Windows 2012 R2中使用此功能,对吗?您使用的是与WebPageTest捆绑在一起的版本吗?哪个版本的WPT?

您的步骤在2012年(R1)为我们工作,但R2给我们的错误看起来像这样:

C:\webpagetest\dummynet\64bit> .\ipfw.cmd
C:\webpagetest\dummynet\64bit>set CYGWIN=nodosfilewarning
C:\webpagetest\dummynet\64bit>ipfw -q flush
  5 [main] ipfw 1896 find_fast_cwd: WARNING: Couldn't compute FAST_CWD pointer.  Please report this problem to the public mailing list cygwin@cygwin.com
C:\webpagetest\dummynet\64bit>ipfw -q pipe flush
  4 [main] ipfw 2944 find_fast_cwd: WARNING: Couldn't compute FAST_CWD pointer.  Please report this problem to the public mailing list cygwin@cygwin.com

你有这个问题吗?在其他地方读到这是由旧版本的Cygwin引起的,我重新编译了最新版本的Cygwin安装的dummynet + ipfw,并将其cygwin1.dll丢弃在输出目录中。当我将此服务安装到我的网络适配器堆栈中时,我得到了不同的错误:

C:\webpagetest\dummynet> .\ipfw.cmd
C:\webpagetest\dummynet>set CYGWIN=nodosfilewarning
C:\webpagetest\dummynet>ipfw -q flush
my_socket failed 2, cannot talk to kernel module
ipfw: socket: No error
C:\webpagetest\dummynet>ipfw -q pipe flush
my_socket failed 2, cannot talk to kernel module
ipfw: socket: No error

此外,它会终止我的DNS:

C:\> Resolve-DnsName google.com
Resolve-DnsName : google.com : No DNS servers configured for local system