I am looking for a way to basically create a clock to store the current windows time. The reason I need a separate clock is I am changing the windows system time using python. So I would like to set the windows clock back to what the time should be after a whole bunch of other java and batch files has executed.
Asked
Active
Viewed 305 times
1 Answers
1
If you are using win32api then use win32api.GetSystemTime and win32api.SetSystemTime:
system_time = win32api.GetSystemTime()
# do stuff here
import subprocess
filepath="D:/path/to/batch/myBatch.bat"
p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
stdout, stderr = p.communicate()
#p.returncode is 0 if success
# more stuff
win32api.SetSystemTime(*system_time)

codefreak
- 6,950
- 3
- 42
- 51
-
If I wanted to call a batch file in the # do stuff here , how would I make python to wait for that batch file to finish and then adjust the system time to what it should be ? – LL. Oct 24 '13 at 14:05
-
check edited answer. Python will execute bat file synchronously so once bat is executed and finished, SetSystemTime will get executed – codefreak Oct 24 '13 at 15:28