I have two NIC ports [port1 & port2] and want to enable Internet Connection Sharing on port1 through either C# or batch script:
Asked
Active
Viewed 5,187 times
0
1 Answers
0
On earlier OS versions, netsh routing could be used, but this no longer works in Win7.
- Have a look at this Powershell snip, otherwise StackOverflow likely has a C# example:
# Register the HNetCfg library (once) RegSvr32 "hnetcfg.dll" # Create a NetSharingManager object $m = New-Object -ComObject HNetCfg.HNetShare # List connections $m.EnumEveryConnection |% { $m.NetConnectionProps.Invoke($_) } # Find connection $c = $m.EnumEveryConnection |? { $m.NetConnectionProps.Invoke($_).Name -eq "Ethernet" } # Get sharing configuration $config = $m.INetSharingConfigurationForINetConnection.Invoke($c) # See if sharing is enabled Write-Output $config.SharingEnabled # See the role of connection in sharing, only meaningful if SharingEnabled is True # 0: Public || 1: Private Write-Output $config.SharingType # Enable sharing # 0: Public || 1: Private $config.EnableSharing(0) # Disable sharing $config.DisableSharing() - How to enable Internet Connection Sharing using command line?
JW0914
- 7,052
- 7
- 27
- 48
Knuckle-Dragger
- 2,043
- 1
- 14
- 19
-
not wokring on win8.1 – Mirodil Apr 14 '16 at 03:52
