使用.NET代码将系统时间同步到域控制器 [英] Sync system time to domain controller using .NET code
本文介绍了使用.NET代码将系统时间同步到域控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有基于时间的测试,需要在测试过程中多次更改系统时间.我希望能够在测试结束时将时间重新同步到域控制器时间.我有任何方法可以使用.NET代码(C#)做到这一点.我正在使用以下位置的p调用功能更改时间:
I have time based tests to run that require changing the system time multiple times during the test. I want to be able to resync the time to the domain controller time at the end of the test. I there any way to do that using .NET code (C#). I am changing the time using the p-invoke function found in:
谢谢
推荐答案
One easy way would be to launch a process and run the NET TIME command (copied from http://blogs.msdn.com/sanket/archive/2006/11/02/synchronizing-machine-time-with-domain-controller.aspx)
using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
Process netTime = new Process();
netTime.StartInfo.FileName = "NET.exe";
netTime.StartInfo.Arguments = "TIME /domain:mydomainname /SET /Y";
netTime.Start();
}
}
这篇关于使用.NET代码将系统时间同步到域控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文