Script required to automatically connect to specific Wi-Fi network

Page 4 of 8 FirstFirst ... 23456 ... LastLast

  1. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #31

    Michael,

    And I was still typing yet again.
    Try3 said:
    I do urge you to check your router to see how you might monitor connections & disconnections to confirm that it is all behaving as you think.
    Instead of that
    - You can check the TS task behaviour by enabling TS All task history [on the right-hand side of the TS window]
    - You can monitor logs of network connections in Event viewer.
    Network connections.zip
    Just unzip it and import it into Event viewer [the import control is on the right-hand side of the Event viewer window].
    - This is probably easier than spending your life finding out how to monitor your router to get this data.

    Denis
      My Computer


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

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

    W10 Tweaker said:
    Thanks, I would much prefer using your single file than what I have now.
    A single VBScript file can do many things. For example, it can make a number of attempts to start the connection and display a message if all the attempts have failed.
      My Computer


  3. Posts : 7,631
    Windows 10 Home 20H2
       #33

    Run the following line of commands via PowerShell.
    Code:
    Get-WinEvent -ProviderName 'Microsoft-Windows-NetworkProfile'|FT -AutoSize > "C:\Scripts\WLAN\Network events.txt"
    "Network events.txt" will be created in your "WLAN" folder. See whether it has useful information
      My Computer


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

    Try3 said:
    Michael,

    And I was still typing yet again.

    You can check the TS task behaviour by enabling TS All task history [on the right-hand side of the TS window]

    You can monitor logs of network connections in Event viewer as well.

    Denis

    Excellent info, thanks. I like your thinking of making no assumptions and actually proving the state is where I want it to be, disconnected during sleep.

    I can always look at the wifi router GUI on another PC to prove this one is not connected during sleep state. That should be revealing enough.
      My Computer


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

    Try3 said:
    Michael,

    I looked at my internet connection [my phone's WiFi hotspot] after logging out and could see that it was still connected.
    I can use the same method to confirm that connections drop off when sleeping.


    You have used code to set things up to reconnect automatically when logging on.


    - When you resume from sleep, I think nothing happens since your TS task triggers are just for logon & 'On Workstation unlock' [not 'reconnect to user session'].


    - So you have done what you said you wanted to do i.e. I was wrong to say there was no difference between what you are doing and just letting it reconnect automatically in the normal way.
    - But it is sleeping rather than logging out that achieves this behaviour.
    - I do urge you to check your router to see how you might monitor connections & disconnections to confirm that it is all behaving as you think.

    Denis

    Thanks Denis, I think your bolded line above was the missing trigger item I required to make this event function consistently. I want to spend more time testing to verify it always connects but this seems to function.

    It seemed to work intermittently before adding that 3rd trigger. I'm now at 4 successful network connect instances out of the last 4 wake from sleep events.


    Script required to automatically connect to specific Wi-Fi network-0306-trigger-connection-user-session.jpg



    I'll test that the network connection drops while sleeping tomorrow. The GUI on my router is very descriptive and easy to see connected PCs.
    Last edited by W10 Tweaker; 06 Mar 2021 at 23:59.
      My Computer


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

    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

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

    Code:
    CreateObject("WScript.Shell").run("rasdial ""PPPoE"" ""User Name"" ""Password"""),0

    Thanks for the idea, I would prefer to use only 1 VBScript without the cmd or .bat, but this still brings up a script error. I require more time for testing but it appears to function with the VBScript and .bat files.

    Script required to automatically connect to specific Wi-Fi network-0306-failed-script.jpg
    ** This is the same error I received it's just not the exact notification. I'm using the VBScript & WLAN connect.bat in C:\Scripts\WLAN .


    Matthew Wai said:
    Code:
    CreateObject("WScript.Shell").run("netsh wlan disconnect ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0
    A single VBScript file can do many things. For example, it can make a number of attempts to start the connection and display a message if all the attempts have failed.
    Thanks for script, I'll file that away and hopefully my testing tomorrow will confirm the network connection disconnects during a sleep state.

    Matthew Wai said:
    Run the following line of commands via PowerShell.
    Code:
    Get-WinEvent -ProviderName 'Microsoft-Windows-NetworkProfile'|FT -AutoSize > "C:\Scripts\WLAN\Network events.txt"
    "Network events.txt" will be created in your "WLAN" folder. See whether it has useful information

    Thanks for that PS. I tweaked it to save on my data drive, it looks great.

      My Computer


  7. Posts : 7,631
    Windows 10 Home 20H2
       #37

    W10 Tweaker said:
    Script required to automatically connect to specific Wi-Fi network-0306-failed-script.jpg
    ** This is the same error I received it's just not the exact notification.
    I have managed to produce the same error at my end.Script required to automatically connect to specific Wi-Fi network-error-reproduced.jpg

    The error message is "The system cannot find the file specified".
    The file specified could be this file netsh

    So, the solution is using the full file path as shown below:
    Code:
    CreateObject("WScript.Shell").Run("C:\Windows\System32\netsh.exe wlan connect ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0
      My Computer


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

    Matthew Wai said:
    I have managed to produce the same error at my end.Script required to automatically connect to specific Wi-Fi network-error-reproduced.jpg

    The error message is "The system cannot find the file specified".
    The file specified could be this file netsh

    So, the solution is using the full file path as shown below:
    Code:
    CreateObject("WScript.Shell").Run("C:\Windows\System32\netsh.exe wlan ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0

    Awesome and thanks for the quick update.


    I'll test this tomorrow AM when I get up.
      My Computer


  9. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #39

    W10 Tweaker said:
    It seemed to work intermittently before adding that 3rd trigger.
    Michael,

    Doesn't adding that third trigger mean you are now back where you started just as if you had set the network to connect automatically?

    Denis
      My Computer


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

    Try3 said:
    Michael,

    Doesn't adding that third trigger mean you are now back where you started just as if you had set the network to connect automatically?

    Denis


    That's a good point Denis, thanks for that.

    I may have to add a conditional start to the task unless I can come up with another work-around.
    I could always select 'Start the task only if the PC is on AC'. I never leave it plugged in when in sleep or shutdown states. I'd just have to remember to hit the power before opening the lid.

    Script required to automatically connect to specific Wi-Fi network-0307-ts-conditional-start.jpg
      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 20:46.
Find Us




Windows 10 Forums