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
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?
1
  • 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.