wsl-clock icon indicating copy to clipboard operation
wsl-clock copied to clipboard

Doesn't work without internet connection

Open felixhorger opened this issue 2 years ago • 3 comments

Hi Stuart, cool solution, saved my day many times :) I observed that it doesn't work if my laptop isn't connected to the internet. Can it be that the time is fetched from the internet and so this fails? Does anything speak against using the windows system time?

Any ideas how your solution could work without internet?

My current workaround is to use something like

d=`powershell.exe -Command 'date'`
sudo date -s "$d"

felixhorger avatar Sep 27 '23 21:09 felixhorger

It didn't work for me even with an Internet connection. This worked though, in PowerShell:

 $date=date;wsl.exe -u root date -s $date

mbomb007 avatar Oct 25 '23 14:10 mbomb007

Interesting, as far as I can see it does use the same commands, just run from outside WSL, it's good to have that solution available as well, plus it might be easier to trigger once windows wakes up from sleep. That's however not my area of expertise, so maybe @stuartleeks can advise on how to run this automatically

felixhorger avatar Nov 13 '23 16:11 felixhorger

I tried creating a scheduled task. The task seems to run, but it doesn't seem to work correctly, as the time is still wrong after sleeping using Modern Standby.

# Schedule a task to set the date inside WSL to the date found by PowerShell.
# It uses "RU" to run as SYSTEM user.
schtasks /Create /F /TN wsl-clock-sync /RU SYSTEM /SC ONEVENT /EC System `
    /TR "powershell -command &{wsl -u root date -s `$(date)}" `
    /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507) or Provider[@Name='Microsoft-Windows-Kernel-General'] and (EventID=1)]]"
Pause

The task action is "Start a program" with powershell -command &{wsl -u root date -s $(date)}

mbomb007 avatar Nov 13 '23 16:11 mbomb007