Is there a way to enabled "Internet Connection Sharing" on Windows 7 (or higher) using command line? Perhaps using "netsh" or a similar command?
4 Answers
I think this question should be on superuser.com. And it is there: https://superuser.com/questions/470319/how-to-enable-internet-connection-sharing-using-command-line.
If you are interested how to do it programmatically – here is the source code at GitHub: https://github.com/utapyngo/icsmanager.
To manage "Internet Connection Sharing" under Win7 you must exec net start SharedAccess
or net stop SharedAccess
.
You can also configure the service using sc config SharedAccess start= disabled
or sc config SharedAccess start= auto
and some other.
Run sc config
to know other options for the "start= ". The space between start=OPTION is mandatory.

- 1,986
- 3
- 32
- 45
-
how can i tell it which adapter's connection should be shared with which other adapter? – peter Sep 16 '14 at 08:50
-
You can't i guess. Follow utapyngos answer :D please. The service configuration hasn't that power cows. – m3nda Sep 16 '14 at 12:57
In my case, I want to use VirtualBox Host-only Adapter alone for two-way communication and Internet sharing, I use Powershell to achieve that.
# fix Windows 10 ICS not working after reboot
# https://support.microsoft.com/en-us/help/4055559/ics-doesn-t-work-after-computer-or-service-restart-on-windows-10
[microsoft.win32.registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedAccess", "EnableRebootPersistConnection", 0x01)
# Enable IP Forwarding
# https://serverfault.com/questions/929081/how-can-i-enable-packet-forwarding-on-windows/929089#929089
Set-NetIPInterface -Forwarding Enabled
# Check IP Forwarding Status
Get-NetIPInterface | Select-Object ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table
# Change the Internet Connection Sharing (ICS) service Startup type to Automatic.
Set-Service SharedAccess -StartupType Automatic
# Start ICS service for now
Start-Service SharedAccess
# Check ICS service Status
Get-Service SharedAccess

- 81
- 5
-
SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedAccess", "EnableRebootPersistConnection", 0x01) -- just found out that this command breaks AnyConnect VPN client – Alexey Novgorodov Oct 19 '21 at 08:53
-
OpenVPN Server - PowerShell line solved Internet persistency problem on WIndows 10 - [microsoft.win32.registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedAccess", "EnableRebootPersistConnection", 0x01) – Niko Feb 23 '23 at 07:08
-
For VPN Server - must add VPN Server Gateway IPs to Firewall Inbound due to VPN subnet is different network and firewall may not allow foreign packets to pass without explicit rule. – Niko Feb 23 '23 at 07:13
- Start cmd as admin and type the following
netsh wlan set hostednetwork mode=allow ssid=networkname key=networkpassword
Press enter then type
NETSH WLAN start hostednetwork
press enter again.
remember to replace the networkname and networkpassword with your preferred names and password respectively

- 183
- 2
- 5
-
1Creating a hosted network is a diffrent step from sharing another interface's connectivity within this network (ICS) – mveroone May 20 '18 at 08:39