Script required to automatically connect to specific Wi-Fi network

Page 1 of 8 123 ... LastLast

  1. Posts : 1,807
    Windows 10 Pro 21H1 19043.1348
       #1

    Script required to automatically connect to specific Wi-Fi network


    Greetings to Windows 10 Guru's, others working towards this qualification and everyone else here to learn.

    I'm using Matthew Wai's CMD & VBScript to manage my updates and have also set all connections to metered.

    As a further measure to prevent surprises and increase security, I've also set my Wi-Fi connection to not automatically connect.

    I use a Desktop shortcut to a simple VBScript to connect to Wi-Fi. This script works great but I've not been successful creating an event in the Task Scheduler to have it run automatically when I logon.

    Could someone please assist me in creating an event in the Task Scheduler using the script I have or recommend an improved approach to accomplish this configuration?

    Thanks in advance for any ideas.
      My Computer


  2. Posts : 7,607
    Windows 10 Home 20H2
       #2

    In the "Program/script" field, enter wscript.exe
    In the "Add arguments (optional)" field, enter the path of your VBScript file as shown below:

    Script required to automatically connect to specific Wi-Fi network-task-running-vbscript.jpg

    Select "At log on" as shown below:

    Script required to automatically connect to specific Wi-Fi network-log-.jpg
      My Computer


  3. Posts : 68,988
    64-bit Windows 11 Pro for Workstations
       #3

    Hello Michael,

    In addition, you could test using the command in option 6 of the tutorial below to connect to a Wi-Fi network you have previously connected to.

    Connect To Wireless Network in Windows 10

    You could use cmd.exe in the Program/script field below, and the command above in the Add arguments field.

    How to Create Task to Run App or Script at Logon in Windows 10
      My Computers


  4. Posts : 1,807
    Windows 10 Pro 21H1 19043.1348
    Thread Starter
       #4

    Thanks Matthew.

    Check, I have confirmed those settings. FYI, right or wrong, I have created a vbscript that triggers a cmd file that identifies the profile and wifi. I had originally had the vbscript triggering a .bat containing the same cmd line as the .cmd file.

    Both connect files, cmd or bat work great using a desktop shortcut but not in the Task Scheduler.


    vbscript;
    Code:
    CreateObject("Wscript.Shell").Run "C:\Scripts\WLAN\WLANx-connect.cmd"
    cmd file;
    Code:
    netsh wlan connect "[ssid]" "{profile name]" 'Wi-Fi"


    Brink said:
    Hello Michael,
    Brink said:


    In addition, you could test using the command in option 6 of the tutorial below to connect to a Wi-Fi network you have previously connected to.

    Connect To Wireless Network in Windows 10

    You could use cmd.exe in the Program/script field below, and the command above in the Add arguments field.

    How to Create Task to Run App or Script at Logon in Windows 10




    Thanks Shawn, I'll have look.
      My Computer


  5. Posts : 68,988
    64-bit Windows 11 Pro for Workstations
       #5

    Does placing a shortcut of the script, .cmd, or .bat file in your Startup folder allow it to run at startup for you?

    Add, Delete, Enable, or Disable Startup Items in Windows 10
      My Computers


  6. Posts : 7,607
    Windows 10 Home 20H2
       #6

    Using CMD will bring up a command window, which could be obtrusive to some users.
    VBScript brings up no window because it works in the background. That's why VBScript is used below:

    Automatically start a PPPoE connection via a script and Task Scheduler
      My Computer


  7. Posts : 7,607
    Windows 10 Home 20H2
       #7

    Brink said:
    Does placing a shortcut of the script, .cmd, or .bat file in your Startup folder allow it to run at startup for you?
    Michael wants it to be run at log on.
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #8

    Michael, try using only the following line of VBScript without CMD script. See whether it works.

    Code:
    CreateObject("WScript.Shell").run("netsh wlan connect ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0

    FYI, I use the following line to start my PPPoE connection.

    Code:
    CreateObject("WScript.Shell").run("rasdial ""PPPoE"" ""User Name"" ""Password"""),0
    Last edited by Matthew Wai; 06 Mar 2021 at 12:45.
      My Computer


  9. Posts : 1,807
    Windows 10 Pro 21H1 19043.1348
    Thread Starter
       #9

    Matthew Wai said:
    Michael wants it to be run at log on.

    Yes thanks, this would be true. I often just use sleep.

    Matthew Wai said:
    Using CMD will bring up a command window, which could be obtrusive to some users.
    VBScript brings up no window because it works in the background. That's why VBScript is used below:

    Automatically start a PPPoE connection via a script and Task Scheduler

    I started out using a .bat and switched it to a cmd after no joy. I'll set it back to .bat .


    Matthew Wai said:
    Michael, try using only the following line of VBScript without CMD script. See whether it works.

    Code:
    CreateObject("WScript.Shell").run("netsh wlan connect ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0
    The red parts are variables. FYI, I use the following line to start my PPPoE connection.

    Code:
    CreateObject("WScript.Shell").run("""rasdial.exe"" ""PPPoE"" ""User Name"" ""Password"""),0
    Thanks, that produced an error.

    Script required to automatically connect to specific Wi-Fi network-0306-failed-script.jpg
    Last edited by W10 Tweaker; 06 Mar 2021 at 18:20.
      My Computer


  10. Posts : 7,607
    Windows 10 Home 20H2
       #10

    W10 Tweaker said:
    Thanks, that produced an error.
    Michael, the file name "WLAN connect.vbs" contains a space, so you have to put quotation marks around the file path.

    "D:\Users\%Username%\Desktop\WLAN connect.vbs"

    W10 Tweaker said:
    Yes thanks, this would be true. I often just use sleep.
    So do I.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:35.
Find Us




Windows 10 Forums