Elangovan
Elangovan

Reputation: 1464

Set date, time & time zone on remote computer using C#

How do you set date, time and the time zone setting of the remote computer using C#? Basically, I want to update the time on selected machines in the network.

Creating time server is not an option as I want to update the time only on the user selected computers. All the remote computers are running windows XP or higher operating system.

Upvotes: 4

Views: 6761

Answers (2)

Abbas
Abbas

Reputation: 6886

Executing a remote process through WMI and .NET are extensively documented online. You can execute the date, time and tzutil DOS utilities to accomplish what you need. However, I think PsExec is the way to go.

You only need to download the 1.6 MB utility once on your computer and use it to execute all kinds of remote processes on your XP machines. Here's how you can change the timezone to Central Time using PsExec:

psexec \\RemPC01 TZUTIL /s "Central Standard Time"

You can wrap this in a bit of .NET code and it should do what you want:

string remoteMachine = "RemPC01";
string appName = "psexec.exe";
string args = string.Format("\\\\{0} TZUTIL /s \"Central Standard Time\"", remoteMachine);
Process.Start(appName, args);

Upvotes: 3

TylarJ
TylarJ

Reputation: 21

I would recommend using PsExec to do this. Maybe using it in combination with your application. It gives you console access to remote computers, and the console command you are looking for is "time" to change the time.

Upvotes: 2

Related Questions