Based on what I have read, if those that have posted said netsh
doesn't work starting at 7 and up- that is incorrect. Now if it's strictly about "netsh routing
", I guess you could be right, but this does work- I am about to show the contents of a batch file I have created that works on Windows 8.1. Instead of getting the usual comments and pieces of information, I am going to try and help those with the full information.
First, you need to make sure the connection you will be sharing is set to actually share the connection. This link here should get you going for that:
Set up a shared Internet connection using ICS (Internet Connection Sharing) at Windows Help.
Open Network Connections by clicking the Start button, and then clicking Control Panel. In the search box, type adapter, and then, under Network and Sharing Center, click View network connections.
Right-click the connection that you want to share, and then click Properties. If you're prompted for an administrator password or confirmation, type the password or provide confirmation.
Click the Sharing tab, and then select the Allow other network users to connect through this computer’s Internet connection check box.
After you've followed the steps above to set up ICS on the host computer, make the following changes on all of the other computers (but not on the host computer).
Open Internet Options by clicking the Start button,
clicking Control Panel, clicking Network and Internet,
and then clicking Internet Options.
Click the Connections tab, and then click Never dial a connection.
Click LAN Settings.
In the Local Area Network (LAN) Settings dialog box,
Under Automatic configuration, clear the Automatically detect settings and Use automatic configuration script check boxes.
Under Proxy server, clear the Use a proxy server for your LAN check box, and then click OK.
Similar instructions are also available here.
To my knowledge, I think this should work for both Windows 7 and 8.
Now since the topic was about a command line solution, this is the batch file contents of how I get a virtual wireless adapter configured and ready to go.
Once it's created, you may have to use the instructions above and make sure you are sharing the source connection with the newly created virtual adapter that will be seen by your wireless devices.
Connection sharing .bat file:
@echo off
set _my_datetime=%date%_%time%
set _my_datetime=%_my_datetime: =_%
set _my_datetime=%_my_datetime::=%
set _my_datetime=%_my_datetime:/=_%
set _my_datetime=%_my_datetime:.=_%
cd\
if NOT EXIST "C:\TEMP\switch.txt" (
GOTO :START
) ELSE (
GOTO :STOP
)
:START
REM Create Temp File for On and Off switch.
ECHO WOOHOO >"C:\TEMP\switch.txt"
REM -- Output everything that is happening into a file called wifi.txt.
REM -- Start out with a timestamp at the top to show when it was done.
REM -- All 'netsh' commands are for setting up the SSID and starting the sharing.
REM -- I stop and start when starting the service just for prosperity.
echo _%_my_datetime% >"C:\TEMP\wifi.txt"
netsh wlan set hostednetwork mode=allow ssid=ITWORKS key=111222333 >> "C:\TEMP\wifi.txt"
netsh wlan stop hostednetwork >>"C:\TEMP\wifi.txt"
netsh wlan start hostednetwork >>"C:\TEMP\wifi.txt"
echo MSGBOX "Wifi Sharing Started!" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
GOTO :END
REM -- This will turn ICS off and give a prompt via VBS that you're turned off.
REM -- I timestamp when the service is turned off in the output file.
REM -- I delete the switch file to let the code know to turn it on when
REM -- when fired off again. Tempmessage is the msgbox used to show the service
REM -- has been turned off. Same for the msgbox above when it's on.
:STOP
echo OFF AT _%_my_datetime% >>"C:\TEMP\wifi.txt"
netsh wlan stop hostednetwork >>"C:\TEMP\wifi.txt"
DEL /Q "C:\TEMP\switch.txt"
echo MSGBOX "Wifi Sharing Stopped!" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
:END
I'll be more than happy to answer questions about this because there is going to be some unique situations and I'd like to help since I had to piece together what I found above.
But to bring this to perspective, this works on Windows 8.1 using an Ethernet connection into a laptop sharing its connection to the virtual adapter. It may work just as well if you are trying to share a source Wireless connection.
2@SmartManoj, it is an option too, but please convert your comment to an answer and copy the script here. A link can become outdated. – utapyngo – 2020-01-23T04:47:40.103
That link doesn't even work. Also, Python on Windows, seriosly? – Free Consulting – 2020-01-28T20:01:22.650
4
Can't try this just now, but you might want to try running Process Monitor and pointing it at your Registry. See what keys/values change when you toggle & apply the setting, then write your script accordingly.
– Iszi – 2012-09-17T20:12:52.240Related question/info over on StackOverflow: Enable Internet Connection Sharing programmatically
– Ƭᴇcʜιᴇ007 – 2013-03-17T17:35:37.417The
– Jacob Krall – 2013-09-20T20:26:42.493Microsoft-Windows-SharedAccess
Unattended Windows Setup component is so close, but it only works at Windows Setup! http://technet.microsoft.com/en-us/library/ff715511.aspx