从 VBS(或 C#/VB)以编程方式安装 Microsoft 环回适配器
我想以编程方式安装 MS 环回适配器,以自动通过 SSH 建立 SMB 隧道。
我在网上找到的所有代码都使用 MS devcon 实用程序,该实用程序不可重新分发(参见 http://support.microsoft.com/kb/311272/en-us)。示例用法(更多示例):
devcon -r install %WINDIR%\Inf\Netloop.inf *MSLOOP
除了可分发性问题之外,理想情况下我希望对生成的设备名称进行一些控制,尽管这可以通过枚举之前和之后的网络适配器并查找新的 MS 环回设备来解决。这有点过分了,不过我想我可以忍受。我的想法是修改一些此代码< /a>.
我目前正在研究 WDK 中的 devcon 源代码,以便按照上面链接的 MS 知识库文章的建议通过 SetupAPI/CfgMgr32 添加环回适配器。有没有更简单/可编写脚本的方法?
如果没有,是否有人有该 SetupAPI/CfgMgr32 路由的一些相对简单的示例代码?
I'd like to programmatically install the MS loopback adapter to automate tunneling of SMB over SSH.
All the code I found on the net uses the MS devcon utility, which is not redistributable (cf. http://support.microsoft.com/kb/311272/en-us). Example usage (more examples):
devcon -r install %WINDIR%\Inf\Netloop.inf *MSLOOP
Apart from the distributability issue, ideally i'd like to have some control over the resulting device name, though that could be fixed by enumerating the network adapters before and after and looking for the new MS loopback device. That's a bit racy, though I think I could live with it. My idea is to adapt some of this code.
I'm currently looking into the devcon source code from the WDK to add the loopback adapter via SetupAPI/CfgMgr32 as the MS KB article linked above suggests. Is there any easier/scriptable way?
If there is none, does anyone have some relatively simple sample code for that SetupAPI/CfgMgr32 route?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想在不编写任何新的 exe 的情况下实现同样的目标,并发现可以使用 cscript 以及 devcon 和 netsh 工具来完成。创建适配器似乎无法控制它将被调用的内容,因此您必须在创建适配器后使用 WMI 接口进行枚举。不幸的是,netsh 的行为取决于您所使用的 Windows 版本,但将以下内容放入名为 create-loopback.vbs 的文件中,它将在 XP 和 2008 服务器上运行。
I wanted to achieve the same thing without writing any new exe to do it and found it can be done with cscript and the devcon and netsh tools. creating the adapter seems to give you no control over what it will be called, so you have to enumerate using the WMI interface after you have created it. Unfortunately netsh behaviour depends on which version of windows you're on, but bung the following in a file called create-loopback.vbs and it will work on XP and 2008 server.
请检查以下线程:
如何安装硬件驱动程序在 Win32 上使用 C
Please check the following thread:
How Do I Install Hardware Driver Using C on Win32
希望我参加聚会还不算太晚 - 无需 devcon/vbs 即可完成此操作(尽管需要许多本机 pinvoke 调用):
为了安装环回适配器,请使用参数
"C: 调用以下方法: \Windows\Inf\netloop.inf"
,*MSLOOP
:以上内容适用于 x64 操作系统。为了使其能够在 x86 操作系统上工作,请将
SP_DEVINFO_DATA
结构中的Pack = 8
更改为Pack = 1
Hope i'm not too late for the party - doing it without devcon/vbs is possible (though many native pinvoke calls are required):
In order to install the loopback adapter, call the following method with the parameters
"C:\Windows\Inf\netloop.inf"
,*MSLOOP
:The above will work on x64 OSs. in order for it to work on x86 OSs, change
Pack = 8
toPack = 1
in theSP_DEVINFO_DATA
struct