-1

Win10物联网开发的小伙伴们好!

我想编写一个程序来设置带有 Windows 10 IoT 的 Raspberry Pi 3 的时间,这样我的时间戳就会正确。

我正在通过Renci.SshNet生成 SSH 连接,并且类似的代码可以正常工作:

Renci.SshNet.SshClient client = new SshClient(IP, Username, PW);
client.Connect();
client.RunCommand("TZUTIL /s \"W.Europe Standard Time\"");
client.RunCommand("shutdown /r /t 0");

但我不可能通过 Set-Date 命令:

I tried all of the following:
// Manual
client.RunCommand("Set-Date " + ((char)34) + "08.06.2016 14:08:45" + ((char)34));
client.RunCommand("Set-Date \"10/3/2015 2:00PM\"");
// Dynamic
System.DateTime dateTime;
dateTime = System.DateTime.Now.AddHours(2);
String datestr = dateTime.ToString();
client.RunCommand("set-date \"" + datestr + "\"");

有一个指南“如何通过 Shell 命令进行连接”,该命令 Set-Date "08.06.2016 14:31:00"运行良好,但相同的代码不会在程序中传递任何内容......

我很高兴有任何帮助!

注意:与如何在 Windows 10 IoT 中设置系统时间有关?

4

1 回答 1

1

您正在混合使用 Windows 命令和 PowerShell 命令。

当您通过 SSH 连接到 Windows 10 IoT Core时,您将连接到 Windows 命令提示符并可以执行 Windows 命令,例如 shutdown.exe。

Set-Date是一个 PowerShell Cmdlet,因此必须从 PowerShell 执行。您可以从 Windows 命令提示符执行 PowerShell 命令,如下所示: PowerShell "Set-Date ""6/16/2016 11:00PM"""

在您的情况下,SSH 客户端的代码将是:
var command = "PowerShell \"Set-Date \"\"6/16/2016 11:00PM\"\"\""; client.RunCommand(command);

于 2016-06-17T02:57:07.873 回答