0

I have two NIC ports [port1 & port2] and want to enable Internet Connection Sharing on port1 through either C# or batch script:

  • I have only been able to find how to start the ICS service, not to enable the option:
    Screenshot1
JW0914
  • 7,052
  • 7
  • 27
  • 48
kcihtrak
  • 11
  • 1
  • 2

1 Answers1

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
  • 7,052
  • 7
  • 27
  • 48
Knuckle-Dragger
  • 2,043
  • 1
  • 14
  • 19