AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

setting the system date and time

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Mon May 02, 2005 2:19 am    Post subject: setting the system date and time Reply with quote

The question was buried in another Support/Help request: is there a simple way to set the system time from an AHK script? I repeat it here, in the hope that more answers will be posted.

Setting the date works perfectly with
Code:
run command.com /C date 05-02-2005
The same does not work with time
Code:
run command.com /C time 20:20:20
If you give the time in the wrong format you see a DOS box opened and a message, that the time is invalid. There you can enter any valid time, but still nothing happens to the Windows system time, like when the time parameter is given right. It looks like a secondary DOS environment is opened and the local time settings don’t affect the main system time. Does anyone know how to get around this?

Interestingly, writing the required date and time commands into a batch file (FileAppend) with their proper parameters and run the batch file instead of the command processor works.
Code:
FileDelete SetDateAndTime.bat
FileAppend Date %Date%`nTime %Time%, SetDateAndTime.bat
run SetDateAndTime.bat
It is a bit slow and we have to be careful not to accidentally overwrite a batch file, which happens to have the same filename. Checking the batch filenames and trying in a loop until there is no collision makes this workaround ugly and big.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1186
Location: switzerland

PostPosted: Mon May 02, 2005 6:01 am    Post subject: Reply with quote

have XP, it works:
Code:
run %COMSPEC% /K time 14:00:10
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Mon May 02, 2005 3:15 pm    Post subject: Reply with quote

Cool! It works. The key is to use cmd.exe (%COMSPEC%), not command.com. Who knew they are so different? Actually, the /C switch has to be used:
Code:
run %COMSPEC% /C time 11:00:00
otherwise a command window is left open. Still, do you know why Date works and Time does not with command.com? (If you have a date you'd better watch the time, too Smile )
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group