Connect to Wi-Fi ad-hoc networks automatically with Windows Vista

Posted on June 26, 2008 at 5:32 am

I recently moved to a new apartment, and lost my small network switch I used for connecting my two laptops and my EEE PC together. All of these devices have a WiFi adapter so I figured I would just set up an Ad-Hoc WiFi network instead of using cables.

This would also mean I could share the Internet connection from my main work laptop and allow me to sit outside in the garden with my sub-notebook and work in the fresh air.

I hit one very annoying fact very early on in this. Namely that Windows Vista does not allow automatic connection to an Ad-Hoc WiFi network, it is seen as a security risk, this meant that every time I started one of the Vista machines I had to manually connect to the network, very annoying at times if I forgot about it. So I decided to solve this problem and I found a way using the Windows Task Scheduler.

Task Scheduler

I first created the Ad-Hoc WiFi network and connected too it, I saved the network setting as a WiFi profile and gave it the name “Decurro”, if you try this yourself you need to remember the name you give the network profile for a later step. I then used the “Create Basic Task” option in Task Scheduler.

Follow the wizard, give the task a name and then choose the “When I log on” option from the “Task Trigger” window. In the next window select “Start a program” and entered the details in the following screenshot, remember to substitute “Decurro” for your own network name. Then complete the wizard.

Run Program

And that is pretty much it, next time you log in to your PC, your Ad-Hoc connection will be connected. I did have one slight problem with a driver not being loaded quickly enough after a reboot and the connection failing, so I added a delay to the task.

To allow for your system to settle down after a login, before opening the network connection, you will need to go back into the Task Scheduler and edit the task you created, choose the “Triggers” tab and click edit, you will be presented with a window that looks like the one below.

Delay Start

Put a tick in the “Delay task for” box and set the delay to 1 minute, this solved the problem I had with my laptop not being in a state to open the network connection right after login, some people might need to do this, others may not. So there you have it, a quick work around to a ridiculous security limitation of Vista.

» Filed Under Computer Tips, Windows Vista

Related Posts

Comments

18 Responses to “Connect to Wi-Fi ad-hoc networks automatically with Windows Vista”

  1. abhishek said on :

    great tips…never know about this…thanks for sharing.


  2. randomemail999 said on :

    Thanks so much for this. I have been looking for way to long for this


  3. Dave said on :

    Works like a charm, thank you for the help.


  4. Dino said on :

    Thanks a lot…was looking for a way to auto connect to my new wireless printer using windows vista on my laptop. This solved my problem.


  5. Laurel said on :

    Very helpful! Thanks for it very much!:)


  6. MARCOS said on :

    handy !!! thanks


  7. Mike said on :

    This doesnt work anymore with Windows 7

    unfortunately, because it also means i cannot login to my server/domaincontroller via my phone :P


  8. James said on :

    Very helpful. Thanks very much.


  9. anonymous said on :

    Thanks a lot, very helpful and if u guys want a task to start without even logging in, than you should click on ‘create task’ not basic task. Check ‘Run if the user is logged on or not’ and fill everything.


  10. Chris said on :

    Great tip! Have needed a way to easily start up my ICS network without having to reconnect using PC. Thanks


  11. dernet said on :

    Excellent program and very functional. Thank you very much.


  12. Abdel said on :

    Very wise solution .. what about when disconnecting ?

    I want to code a small tool to do that .. maybe watches the connectivity –> if disconnected -> Reconnect

    Thanks a lot.


  13. Kyle said on :

    Thanks for the tip. I’m on Ubuntu and I’m using adhoc to share my internet with my wife’s Vista computer and this will work great.

    I would also like to do something like Abdel said with watching the connectivity. Sometimes when I restart my computer (the one hosting the adhoc network and sharing internet) my wife’s computer does not disconnect from the adhoc network but instead just switches to having limited connectivity.

    I’m trying to figure out if it’s possible to disconnect and reconnect if there is limited connectivity.

    Thanks!


  14. allan said on :

    This is an awesome tip!
    I want to be able to automatically connect to an Ad-Hoc network (my cell phone provides one) when nothing else is available, but connect to an Infrastructure network if one is available.

    I managed to find a solution based on your post.
    Run the following .CMD script as a scheduled task.
    Hope this helps someone!

    @echo off
    setlocal enabledelayedexpansion enableextensions
    netsh wlan show interfaces|find /i /c “Infrastructure” >NUL && (
    echo *** Already connected to an Infrastructure-based Wifi Network – Nothing to do.
    exit /b 0
    )

    if [%1] == [] (
    echo Usage: %~dp0 Ad-Hoc SSID
    echo.
    echo Fix Windows’ behavior which is to never auto-connect to an ad-hoc network.
    echo With this script, the ad-hoc network is considered lower priority than predefined infrastructure-based networks
    echo But if no such prefined networks are available, the ad-hoc network will be auto-connected.
    echo .
    exit /b 0
    ) else (
    Set ADHOC=%1
    )

    REM We know we are not on an Infrastructure Wifi
    REM Assume the Wifi is disconnected
    Set /a onWifi=0

    REM Check for an ad-hoc network
    netsh wlan show interfaces | find /i /c “Adhoc” >NUL && (
    Set /a onWifi=1
    )

    if !onWiFi! EQU 1 (
    echo *** We are connected to the Ad-Hoc network.
    echo *** Checking for an alternative.
    for /F “delims=: tokens=2″ %%N in (‘netsh wlan show networks^|find “SSID” ‘) do @(
    Set SSID=%%N
    if “!SSID!” == ” ” (
    REM — echo Skipping Network: !SSID!
    ) else (
    if /i “!SSID!” == ” !ADHOC!” (
    REM — echo Skipping ad-hoc !SSID!
    ) else (
    REM — echo Found Network: !SSID!
    for /F “tokens=*” %%P in (‘netsh wlan show profiles^|find “!SSID!” ^|find /i /v “!ADHOC!” ‘) do @(
    Set Profile=%%N
    Set Profile=!Profile:All User Profile :=!
    echo *** !SSID! is available
    Set ConnectNetwork=!SSID!
    )
    )
    )
    )
    ) else (
    echo *** We are not connected to any network.
    echo *** Try connecting to !ADHOC!
    for /F “delims=: tokens=2″ %%A in (‘netsh wlan show networks^|find /i “!ADHOC!” ‘) do @(
    Set ConnectNetwork=%%A
    Set ConnectNetwork=!ConnectNetwork: =!
    )
    )

    if “!ConnectNetwork!” == “” (
    echo *** Sorry, no network could be found.
    ) else (
    echo *** Connecting to !ConnectNetwork!
    netsh wlan connect name=!ConnectNetwork! >NUL 2>NUL || (
    echo Sorry, unable to connect
    exit /b 0
    )
    )


  15. William said on :

    Hey , doesnt this work in the os with Windows 7? please help! :(


  16. Steve said on :

    Hi, this seems to be exactly the solution I’m looking for in order to get my adhoc connection to my wireless printer to connect automatically. I can’t seem to get any success though and I’m wondering how do I save network settings as a WiFi profile? Thanks in advance for any help!!


  17. Joseph said on :

    Very useful tip! I have a Daihinia network (which is based on ad-hoc) and needed my computers to automatically connect upon start.

    More details on Daihinia at daihinia.com/about


  18. Mathew said on :

    OMG THANK YOU SOOO MUCH!!!


Please post your comments/suggestions!