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

share|improve this question

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 enabledWrite-Output $config.SharingEnabled# See the role of connection in sharing# 0 - public, 1 - private# Only meaningful if SharingEnabled is TrueWrite-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?

share|improve this answer
not wokring on win8.1– MirodilApr 14 '16 at 3:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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