| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Mon May 02, 2005 2:19 am Post subject: setting the system date and time |
|
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1186 Location: switzerland
|
Posted: Mon May 02, 2005 6:01 am Post subject: |
|
|
have XP, it works:
| Code: | | run %COMSPEC% /K time 14:00:10 |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4078 Location: Pittsburgh
|
Posted: Mon May 02, 2005 3:15 pm Post subject: |
|
|
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 ) |
|
| Back to top |
|
 |
|