How to set system time in Windows 10 IoT?

后端 未结 8 2490
星月不相逢
星月不相逢 2020-12-31 05:12

Is there a way to set system time from my app running on a Raspberry Pi 2 in Windows 10 IoT Core Insider Preview?

This doesn\'t work for lack of kernel32.dll

<
8条回答
  •  时光取名叫无心
    2020-12-31 05:48

    You can call any PowerShell routine from C# on UWP/IoT-Core systems. As such, the PowerShell commands are always available in/to your App.

    For an example, see the ProcessLauncher sample on GitHub.

    ALTERNATIVE, schedule a startup PS script as follows:

    Run PowerShell as an Administrator on the board (Press the Windows button, and start typing PowerShell, right click on the icon and select “Run as Administrator”).

    Set-ExecutionPolicy RemoteSigned

    PuTTy to RPi as admin and:

    setx PATH "%PATH%;C:\Windows\System32"

    schtasks /create /tn "StartupPowerShell" /tr c:\Startup.bat /sc onstart /ru SYSTEM

    Startup.bat

    powershell -command "C:\IotCoreStartup.ps1"
    

    IotCoreStartup.ps

    $logFile = 'C:\StartupLog.txt'
    
    get-date > $logFile
    
    tzutil /s "UTC" >> $logFile
    
    # set alternate time servers
    "Setting additional time servers" >> $logFile
    w32tm /config /syncfromflags:manual /manualpeerlist:"0.windows.time.com 1.pool.ntp.org" >> $logFile
    

    Deleting a scheduled task if required:

    schtasks /Delete /TN "StartupPowerShell"

    Running a scheduled task if to test:

    schtasks /Run /tn "StartupPowerShell"

提交回复
热议问题