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?
not wokring on win8.1 – Mirodil – 2016-04-14T03:52:55.183