2016-06-08 63 views
-1

Win10物联网开发的同事们!SSH通过代码在Windows 10上设置日期IoT

我想写一个程序来设置我的Raspberry Pi 3与Windows 10 IoT的时间,所以我的时间戳将是正确的。

我生成通过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"); 

但它是不可能的,我通过这组最新命令:

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 + "\""); 

有是一个guide“如何通过壳命令连接”和命令 Set-Date "08.06.2016 14:31:00"工作得很好,但相同的代码不通过程序中的任何东西...

我很高兴有任何帮助!

注:相关How to set system time in Windows 10 IoT?

+0

“这是不可能的,我通过这组最新的命令“当你尝试时会发生什么?你有没有收到任何错误信息?错误信息说什么? – Kenster

+0

你的'datestr'看起来像什么?与08.06.2016 14:08:45'格式相同吗?你有没有试图用自定义格式说明符和特定文化来设置它的格式呢? –

+0

@Kenster 没有错误消息,它只是停在那里,直到Timer再次调用方法。它只是没有设置我的树莓上的时间既没有提交“设置日期”命令和所有命令。 @SonerGönül Specific Culture同一问题: 'DateTime dt = DateTime.Now; Thread.CurrentThread.CurrentCulture = new CultureInfo(“de-DE”); CultureInfo ci = new CultureInfo(“de-DE”); client.RunCommand(“Set-Date \”“+ dt.ToString(ci)+”\“”);' 任何想法还可能是什么? – Kyagos

回答

1

你混合的Windows命令和PowerShell命令。

当您连接到Windows命令提示符并且可以执行Windows命令(如shutdown.exe)时,您可以使用SSH to Windows 10 IoT Core

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);

+0

Thx!不幸的是,连接仍然不会推送它 您是否意味着WC Promts中不支持某些PowerShell命令?这可能导致这样的结论:来自Rencii的资源不是通过C#程序启动“设置日期”的最佳方式 – Kyagos

相关问题