I have two NIC ports(port1 & port2) in my windows machine. I want to enable internet connection sharing option on port1 through any script (either c# or batch is preferred). I have googled and able to get only how to start the ICS service but not to enable that option. I have given an image for reference.

enter image description here


On earlier OS, we had a batch method netsh routing but this no longer works in W7. Have a look at this powershell snip and see if it can help. Otherwise, I bet somewhere at stackoverflow is 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
# 0 - public, 1 - private
# Only meaningful if SharingEnabled is True
Write-Output $config.SharingType

# Enable sharing (0 - public, 1 - private)

# Disable sharing


How to enable Internet Connection Sharing using command line?

  • not wokring on win8.1 – Mirodil Apr 14 '16 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.