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,719 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
- 9,096
Knuckle-Dragger
- 2,133
