Skip to main content
3 of 3
Applied syntax highlighting and correct markdown for weblinks ; Removed dead link ; Grammatical corrections
JW0914
  • 8.2k
  • 7
  • 30
  • 50

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?
Knuckle-Dragger
  • 2.1k
  • 1
  • 15
  • 19