Setting systems date and time - Windows

Hi Guys,

I am trying to write a script that updates the computers time to our
servers time. On Ubuntu box it works like a charm but cant get it to
work on a Windows box. Here is the code:

def self.get_time
begin
response = get(“xxxxxxxx”, :basic_auth => { :username => “xxxxx”,
:password => “xxxxxx”})
if response.code == 200
puts response.body
else
puts “Couldnt get server time”
end

rescue
  puts "Couldn't get Time"
end

response.body

end

def self.sync
begin
time = self.get_time
system(“date -s +%m-%d-%Y +%T -s “#{time}””)

rescue
  puts "Set Error"
end

end
end

Output:

2011-11-03 11:35:47
The system cannot accept the date entered.
Enter the new date: (mm-dd-yy)

Are there alternative methods for setting the systems date and time?

Thanks

On Nov 3, 2011, at 10:41 AM, Saul G. wrote:

Enter the new date: (mm-dd-yy)

Using NTP is not an option?

Regards,
Florian

On Thu, Nov 3, 2011 at 10:41 AM, Saul G. [email protected] wrote:

Output:

2011-11-03 11:35:47
The system cannot accept the date entered.
Enter the new date: (mm-dd-yy)

Are there alternative methods for setting the systems date and time?

On Windows (client as well as Server), by default only members of the
System Service and Administrator groups can change system-wide
settings like the time and date.

You can change this via Group Policy, including for workstations not
connected to an Active Directory server.

If, in your case, the PCs are connected to an AD server, leave
system time changes to the AD server, otherwise you’ll get to know the
Kerberos protocol more intimately than any sane person should. :wink:

The question is, why don’t you let Windows’ and *NIX NTP
services/daemons deal with adjusting time and date (you can set up
your own NTP server, if your machines are disconnected from the
Internet).


Phillip G.

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

On Winows, you’d have to use two commands - date and time. Also,
it appears that their format is system-dependent - according to what
you’ve written, for you it’s mm-dd-yy (for date), and on my box it’s
yy-mm-dd (the language is set to Polish).

– Matma R.