简体   繁体   English

Windows-7:在隐藏时禁用 inte.net 连接共享 on.network 适配器 state?

[英]Windows-7:Disable internet connection sharing on network adapter when it's in hidden state?

I'm trying to share inte.net over a.network adapter on windows-7 using NetConLib.dll .我正在尝试使用 NetConLib.dll 在 windows-7 上通过 a.network 适配器共享NetConLib.dll

In order to do this, inte.net sharing should be disabled on all other.network adapters.为此,应在所有其他网络适配器上禁用互联网共享。

In normal cases.正常情况下。 I can iterate all the installed.network adapters and disable sharing on them.我可以迭代所有 installed.network 适配器并禁用它们的共享。 However , sometimes when the.network device is unplugged , the adapter is hidden in windows. But it's properties is still present inside windows registry.然而,有时当网络设备被拔掉时,适配器隐藏在 windows 中。但它的属性仍然存在于 windows 注册表中。

I can't even find the adapter in Control Panel.我什至在控制面板中找不到适配器。 And off course, can't iterate it using the NetConlib library.当然,不能使用NetConlib库对其进行迭代。


Possible scenarios.可能的场景。

  • The easiest way, would be using a windows command to disable inte.net sharing on all the adapters.最简单的方法是使用 windows 命令禁用所有适配器上的 inte.net 共享。 Regardless of their visibility.不管他们的知名度。

    Is that possible in anyway?无论如何,这可能吗?

  • The second solution is to recover the.network adapter from hidden state, so that NetConlib could iterate through it and disable it.第二种解决方案是从隐藏的 state 中恢复 .network 适配器,以便NetConlib可以遍历它并禁用它。

    I tried to find the adapter's properties in windows registry and unhide it, But couldn't find anything .我试图在 windows 注册表中找到适配器的属性并unhide它,但找不到任何东西

Any solution?任何解决方案?


@erm3nda. @erm3nda。

Thank you for the informative answer.感谢您提供翔实的答案。 Although it didn't fix the problem I'm facing with NetConlib .虽然它没有解决我面临的问题NetConlib

SC config correctly shuts down ICS service. SC 配置正确关闭 ICS 服务。 But the shared.network adapter continues on being flagged as Shared 1 .但是 shared.network 适配器继续被标记Shared 1 So ICS service being turned off doesn't seem to affect the adapters' settings.因此关闭ICS 服务似乎不会影响适配器的设置。

Quite interestingly;很有趣; when you try to share another adapter using windows GUI ( Right click on adapter -> Properties -> Share ), a message is prompted telling you当您尝试使用 windows GUI 共享另一个适配器时( Right click on adapter -> Properties -> Share ),系统会提示一条消息告诉您

"there is another adapter being shared currently, your new adapter will be shared instead". “当前有另一个适配器正在共享,您的新适配器将被共享”。 You click ok and it's done.你点击确定就完成了。

I've been digging the entire inte.net the whole afternoon to see if there are other solutions using CMD commands.我整个下午都在挖掘整个 inte.net,看看是否有其他使用 CMD 命令的解决方案。

Maybe there could be a away to share an adapter with a command.也许可以通过命令共享适配器。 This way windows would handle disabling other adapters.这样 windows 将处理禁用其他适配器。 In a similar way as when the GUI is used.与使用 GUI 时的方式类似。


1: Windows tells you which adapter is currently being shared in Control Panel\Network and Inte.net\Network Connections ). 1: Windows 告诉您当前在Control Panel\Network and Inte.net\Network Connections中共享哪个适配器)。

Possible solution 1: Disable ICS at all. 可能的解决方案1:完全禁用ICS。 You can stop ICS service, so none of the connections will be at sharing status and will not conflict with NetConLib.dll . 您可以停止ICS服务,因此所有连接都不会处于共享状态,也不会与NetConLib.dll冲突。 (Not sure about the hidden ones, you must try). (不确定隐藏的,你必须尝试)。

You can manage it from command line using: net start SharedAccess or net stop SharedAccess 您可以使用以下命令从命令行进行管理: net start SharedAccessnet stop SharedAccess

Also, if you need to disable it from reboot to, must disable service using: sc config SharedAccess start= disabled 此外,如果您需要在重新启动时禁用它,必须使用以下命令禁用服务: sc config SharedAccess start= disabled

Notes and references: 注释和参考:

  • Executing sc config will display "start= OPTIONS" and some other. 执行sc config将显示“start = OPTIONS”和其他一些。 The space below = and option is mandatory. 下面的空格=和选项是必需的。 You can check result running services.msc from Run or cmd. 您可以从Run或cmd检查运行services.msc结果。
  • Exec net to display OPTIONS. 执行net以显示OPTIONS。 The name of service is on the services.msc list under "Name of the service" label from ICS service. 服务名称位于ICS服务的“服务名称”标签下的services.msc列表中。
  • netsh routing is not on Win7 anymore, so you only can start/stop/enable/disable but not enable for a particular Interface. netsh routing不再在Win7上,因此您只能启动/停止/启用/禁用但不能启用特定接口。 You must set by handMouse... This not work under Win7 ICS into XP system 你必须通过handMouse设置......这不能在Win7 ICS下运行到XP系统中
  • Sc Config command was from this cool documentation i found today . Sc Config命令来自我今天发现的这个很酷的文档

Possible solution 2: Remove ghost interfaces? 可能的解决方案2:删除ghost界面? I try also around Adapters and interfaces into registry and do not see anything about show/hid/ghost/enabled or similar. 我还尝试将适配器和接口放入注册表中,并且看不到有关show / hid / ghost / enabled或类似内容的任何信息。 I also search here kb 314053 for registry conf. 我也在这里搜索kb 314053 for registry conf。

I can suggeest try Possible solution 1 :) or directly delete hidden/ghost adapters. 我可以makegeest尝试可能的解决方案1 ​​:)或直接删除隐藏/鬼适配器。 You can do it by two ways. 你可以通过两种方式来做到这一点。 Devcon remove option will delete also drivers. Devcon删除选项也将删除驱动程序。

Basic usage for find netcards devcon findall =net , also you can devcon findall =net *ndis* to list all ndis cards. 查找netcards devcon findall =net基本用法,也可以devcon findall =net *ndis*列出所有ndis卡。 Basic usage for remove will be devcon remove =net *ndis* to remove all ndis card type. remove的基本用法是devcon remove =net *ndis*删除所有ndis卡类型。

I try also enable/disable commands but nothing has change into my network interfaces list. 我也尝试启用/禁用命令,但我的网络接口列表没有任何变化。 I removed my own wifi card to test it :) Anyway, i didn't notice any option about "Unhide" feature for such devices from conections panel. 我删除了自己的wifi卡来测试它:)无论如何,我没有注意到任何选项关于这些设备的“取消隐藏”功能来自连接面板。

NEW EDIT (Too much verbose, right?) 新编辑(太冗长了,对吧?)

I found a tool called ics-manager from this superuser post. 从这个超级用户帖子中找到了一个名为ics-manager的工具 - read answer #3 You can download directly from utapyngo's Git project page . - 阅读答案#3您可以直接从utapyngo的Git项目页面下载。

It's based on .Net Framework 4. Yo must download and run the build.bat to compile both exe's (You got also the C# source). 它基于.Net Framework 4.Yo必须下载并运行build.bat来编译两个exe(你也得到了C#源代码)。 The solution is to get only the compiled IcsManager.exe (command line version) with the only needed library IcsManagerLibrary.dll. 解决方案是仅使用唯一需要的库IcsManagerLibrary.dll获取已编译的IcsManager.exe(命令行版本)。

This app is using also NETCONLib.dll , so you can use it, or read the source to see wich is the correct function you need to do it and implement on your development. 此应用程序也使用NETCONLib.dll ,因此您可以使用它,或者阅读源代码以查看您需要执行此操作并在开发时实施的正确功能。

If you got problems with the Ip range "192.168.137.1", you can set from Registry permanently, or run netsh interface ipv4 set address name="YOUR-INTERFACE" source=static addr=192.168.2.1 mask=255.255.255.0 . 如果您遇到Ip范围“192.168.137.1”的问题,您可以从Registry永久设置,或运行netsh interface ipv4 set address name="YOUR-INTERFACE" source=static addr=192.168.2.1 mask=255.255.255.0 You will got ugly errors from launch the netsh interface using tilde or accutes into interfaces name (Spanish default ethernet name is "Conexión de áreal local"... a joke). 你会发现使用tilde或nettes进入netsh interface丑陋错误(西班牙语默认以太网名称是“Conexióndeárealocal”......一个笑话)。

Note: You can pack all at once, using first a Bat to call the IcsManager.exe' with the arguments needed, then launch the netsh configure command later from same batch to full configure. 注意:您可以一次打包,首先使用Bat来call所需参数的IcsManager.exe,然后再从同一批次启动netsh configure命令到完全配置。

Comment: About the prompt when try to overwrite an shared connection, it's surely because only one could be shared. 注释:关于尝试覆盖共享连接时的提示,肯定是因为只能共享一个。 I also see, they are configured as Public and Home to set the pair, but i can't find where's the registry key...Also make some exports from reg and using Diffs, no lucky. 我也看到,他们被配置为公共和家庭设置对,但我找不到注册表项的位置...也从reg和使用Diffs进行一些导出,没有幸运。 I got stuck at diffs and start to search "ICS C++ and C#" on Google, then found it. 我陷入困境并开始在Google上搜索“ICS C ++和C#”,然后找到它。

Extra: I got the netsh it into a bat, and it's launched for Windows Task when a Ethernet cable is plugged (Here is the howto) in order to use with Android Reverse Tethering. 额外的:我把netsh变成了一个蝙蝠, 当插入以太网电缆时它是为Windows Task启动的(这是howto) ,以便与Android Reverse Tethering一起使用。 As you can see, im too interesting into your question because it makes me research better and also learned a lot. 正如你所看到的,我对你的问题太有趣了,因为它让我的研究更好,也学到了很多东西。

Sorry about my bad English. 抱歉我的英语不好。 Im not. 我不是。 Regards. 问候。

I found that by going into Device Manager, you can show the Hidden Devices and try to disable the internet sharing on the adapters. 我发现通过进入设备管理器,您可以显示隐藏设备并尝试禁用适配器上的Internet共享。

Hopefully this is near what you are asking. 希望这接近你的要求。 Good luck! 祝好运!

Atm 自动取款机

Source: http://msdn.microsoft.com/en-us/library/windows/hardware/ff553955%28v=vs.85%29.aspx 来源: http//msdn.microsoft.com/en-us/library/windows/hardware/ff553955%28v=vs.85%29.aspx

I'm about 10 years late to the party, but the complete solution to this problem is nowhere else on the inte.net.我迟到了大约 10 年,但这个问题的完整解决方案在 inte.net 上无处可寻。 In order to disable inte.net connection sharing for a device that is unplugged or uninstalled you will need to:要为未插入或卸载的设备禁用 inte.net 连接共享,您需要:

  • Clear the shared access registry清除共享访问注册表
  • Clear the WMI sharing entry for the device清除设备的 WMI 共享条目
  • Disable sharing through the.netcon library通过 .netcon 库禁用共享

Clearing the registry:清除注册表:

You need to set two registry keys to 0xFFFFFFFF :您需要将两个注册表项设置为0xFFFFFFFF

  • HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedAccess\PrivateIndex and HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedAccess\PrivateIndex
  • HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedAccess\PublicIndex

For example in powershell:例如在 powershell 中:

Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedAccess" -Name "PrivateIndex" -Value 0xFFFFFFFF
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\SharedAccess" -Name "PublicIndex" -Value 0xFFFFFFFF

Clear the WMI sharing entry for the device:清除设备的 WMI 共享条目:

For every HNet_ConnectionProperties you must ensure IsIcsPublic and IsIcsPrivate is set to false .对于每个HNet_ConnectionProperties ,您必须确保IsIcsPublicIsIcsPrivate设置为false You can view which interface has IsIcsPublic or IsIcsPrivate set in powershell:可以在powershell查看哪个接口设置了IsIcsPublic或者IsIcsPrivate

Get-CimInstance -ClassName 'HNet_ConnectionProperties' -Namespace 'root\Microsoft\HomeNet' | Format-Table

Unfortunately, the Set-CimInstance cmdlet does not appear to work in this scenario, so we have to choose another language.不幸的是, Set-CimInstance cmdlet 在这种情况下似乎不起作用,所以我们必须选择另一种语言。 Fortunately, code to set these values to false can be found online.幸运的是,可以在网上找到将这些值设置为false的代码。 For example, here is some C# that performs this task (attibuted to utapyngo )例如,这里有一些 C# 执行此任务(归于 utapyngo

    public static void CleanupWMISharingEntries()
    {
        var scope = new ManagementScope("root\\Microsoft\\HomeNet");
        scope.Connect();

        var options = new PutOptions();
        options.Type = PutType.UpdateOnly;

        var query = new ObjectQuery("SELECT * FROM HNet_ConnectionProperties");
        var srchr = new ManagementObjectSearcher(scope, query);
        foreach (ManagementObject entry in srchr.Get())
        {
            if ((bool)entry["IsIcsPrivate"])
                entry["IsIcsPrivate"] = false;
            if ((bool)entry["IsIcsPublic"])
                entry["IsIcsPublic"] = false;
            entry.Put(options);
        }
    }

... and some vbscript (attributed to billchaison ): ...和一些 vbscript (归因于billchaison ):

set WMI = GetObject("WinMgmts:\root\Microsoft\HomeNet")
set objs1 = WMI.ExecQuery("SELECT * FROM HNet_ConnectionProperties WHERE IsIcsPrivate = TRUE")
for each obj in objs1
    obj.IsIcsPrivate = FALSE
    obj.Put_
next
set objs2 = WMI.ExecQuery("SELECT * FROM HNet_ConnectionProperties WHERE IsIcsPublic = TRUE")
for each obj in objs2
    obj.IsIcsPublic = FALSE
    obj.Put_
next

Disable sharing through the.netcon library:通过 .netcon 库禁用共享:

This part you probably already know, but for completeness, here is some powershell that does it:这部分你可能已经知道了,但为了完整起见,这里有一些 powershell 可以做到这一点:

regsvr32.exe /s hnetcfg.dll
$NetShare = New-Object -ComObject HNetCfg.HNetShare

foreach ($RawConnection in $NetShare.EnumEveryConnection) {
    $Sharing = $NetShare.INetSharingConfigurationForINetConnection.Invoke($RawConnection)
    $Sharing.DisableSharing()
}

The documentation for the relevant COM APIs for.netcon can be found on MSDN .netcon 的相关 COM API 的文档可以在MSDN上找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM