Script required to automatically connect to specific Wi-Fi network

Page 5 of 8 FirstFirst ... 34567 ... LastLast

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

    W10 Tweaker said:
    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.
    Michael,

    Since you are happy to remove AC power then use hibernation instead of sleep and the wakeup problem disappears anyway.
    - TS cannot wake from hibernation unless AC is available.
    - This undocumented limitation has existed since WinXP if not earlier.
    - The only exception I have seen has been for a computer that had S0 Modern standby.
    - This solution would allow you to revert the network connection to automatically connect.

    Denis
      My Computer


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

    When I sign out, the Event ID is 7002. When I log on, it is 7001.

    Script required to automatically connect to specific Wi-Fi network-winlogon.jpg

    Michael may consider using the following settings:

    Script required to automatically connect to specific Wi-Fi network-7001.jpg

    See whether it is more reliable than "At log on", as Michael said the following:
    W10 Tweaker said:
    It seemed to work intermittently

    Run the following line of commands via PowerShell. You should get a list of "User Logon Notification".

    Get-WinEvent -FilterHashtable @{LogName='System';ID='7001'}|FT -AutoSize
      My Computer


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

    Try3 said:
    Michael,

    Since you are happy to remove AC power then use hibernation instead of sleep and the wakeup problem disappears anyway.
    - TS cannot wake from hibernation unless AC is available.
    - This undocumented limitation has existed since WinXP if not earlier.
    - The only exception I have seen has been for a computer that had S0 Modern standby.
    - This solution would allow you to revert the network connection to automatically connect.

    Denis


    Thanks for that idea. The OS is using an SSD so I've not been using hibernation since.
    No S0 available on this PC.

    I have to wonder about this intermittent behavior and if it could be related to the using the TS without AC power. Intermittent behavior with a digital device is certainly not logical.

    I've reverted back to my original vbs & .bat files to accomplish the reconnect as I've been unsuccessful with 1 script file.
    I've added an additional trigger as per Matthew's suggestion in post #42, to use Event 7001. Thanks Matthew.
    I've removed the condition of 'Start the task only if the PC is on AC' until I'm satisfied that the process is reliable.
    I've also reset the count on my reliability test to connect.
    I'll try to keep this count updated where-ever it exists in the most recent post.


    Reliability Count;
    4 successful connects for the past 6 attempts.

    Also, added trigger again, 'Start the task only if the PC is on AC'.
    Last edited by W10 Tweaker; 08 Mar 2021 at 10:33.
      My Computer


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

    Matthew Wai said:
    When I sign out, the Event ID is 7002. When I log on, it is 7001.

    Script required to automatically connect to specific Wi-Fi network-winlogon.jpg

    Michael may consider using the following settings:

    Script required to automatically connect to specific Wi-Fi network-7001.jpg

    See whether it is more reliable than "At log on", as Michael said the following:


    Run the following line of commands via PowerShell. You should get a list of "User Logon Notification".

    Get-WinEvent -FilterHashtable @{LogName='System';ID='7001'}|FT -AutoSize

    Triggering on Event 7001 looks like a great idea, added new trigger. Thanks for that PS script, it appears that there have been many 7001 Events. I keep moving in & out of sleep to test functionality of the Task Scheduler script.

    After I gain more confidence in the reliability, I'll remove 'At logon' and possibly 'After connection to a user session'.
    I did try the following script without success. And yes I caught the originally missing 'connect'.

    CreateObject("WScript.Shell").Run("C:\Windows\System32\netsh.exe wlan connect ""[ssid]"" ""{profile name]"" ""Wi-Fi"""),0


    I tried a few tweaks, syntax etc but couldn't get it to function. I noticed in some earlier posted scripts, there was a space after 'run', does the '(' negate the requirement for a space?
      My Computer


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

    Let's get back to basics. Copy the following line into this file: C:\Scripts\WLAN\Netsh.vbs

    CreateObject("WScript.Shell").Run"%WinDir%\System32\netsh.exe"

    Just double-click on "Netsh.vbs" and see whether the Netsh window will pop up.

    W10 Tweaker said:
    I noticed in some earlier posted scripts, there was a space after 'run', does the '(' negate the requirement for a space?
    Neither a bracket nor a space is required in practice.
      My Computer


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

    Matthew Wai said:
    Let's get back to basics. Copy the following line into this file: C:\Scripts\WLAN\Netsh.vbs

    CreateObject("WScript.Shell").Run"%WinDir%\System32\netsh.exe"

    Just double-click on "Netsh.vbs" and see whether the Netsh window will pop up.


    Affirmative, this leaves a cmd window open. Thanks.


    Script required to automatically connect to specific Wi-Fi network-0308-netsh-cmd-window.jpg



    Matthew Wai said:
    Neither a bracket nor a space is required in practice.

    Thanks for that info. If the bracket or space are not required, is the purpose only to make the script easier to comprehend? Almost comparable to a rem statement?
      My Computer


  7. Posts : 18,032
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #47

    Hello @W10 Tweaker,

    W10 Tweaker said:
    If the bracket or space are not required, is the purpose only to make the script easier to comprehend? Almost comparable to a rem statement?

    Different people have their own set ways of writing code that suits them. I personally use spaces and code blocks etc as opposed to a long string of commands in one line because it makes the code easier to read and troubleshoot.

      My Computer


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

    Paul Black said:
    Hello @W10 Tweaker,




    Different people have their own set ways of writing code that suits them. I personally use spaces and code blocks etc opposed to a long string of commands in my code because it makes the code easier to read and troubleshoot.



    Thanks Paul, that makes sense to me. Anything we can do to make things more apparent just makes most everyone's life easier, in the long run. There's very little point to be secretive about this stuff.
      My Computer


  9. Posts : 18,032
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #49

    Hello @W10 Tweaker,

    W10 Tweaker said:
    Thanks Paul, that makes sense to me. Anything we can do to make things more apparent just makes most everyone's life easier, in the long run. There's very little point to be secretive about this stuff.

    You are VERY welcome.

    I agree. I have OCD so it is slightly different for me. I think people are more inclined to run code given here if it looks structured, clean, and tidy, rather than long strings of code which are VERY hard to decipher.
      My Computer


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

    Paul Black said:
    … long strings of code which are VERY hard to decipher.
    And hence very difficult or impossible to debug & maintain.

    Denis
      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 03:33.
Find Us




Windows 10 Forums