How to enable Internet connection sharing through script

0

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

kcihtrak

Posted 2014-01-21T12:06:03.347

Reputation: 11

Answers

0

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)
$config.EnableSharing(0)

# Disable sharing
$config.DisableSharing()

http://earthwithsun.com/questions/470319/how-to-enable-internet-connection-sharing-using-command-line

How to enable Internet Connection Sharing using command line?

Knuckle-Dragger

Posted 2014-01-21T12:06:03.347

Reputation: 1 817

not wokring on win8.1 – Mirodil – 2016-04-14T03:52:55.183