Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; 'python': 0.08; '"current': 0.09; 'disable': 0.09; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'prefer.': 0.09; 'pywin32': 0.09; 'enabling': 0.13; 'ideally': 0.15; '(),': 0.16; '(none,': 0.16; 'happens.': 0.16; 'privilege': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:Setting': 0.16; 'win32api': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.16; 'example.': 0.18; 'cc:no real name:2**0': 0.20; 'seems': 0.20; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'work,': 0.23; 'command': 0.24; 'testing': 0.24; 'code': 0.25; 'settings': 0.26; "i'm": 0.27; 'skip:[ 10': 0.27; 'import': 0.28; 'happening': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.30; 'not.': 0.30; 'subject:time': 0.30; 'ctypes': 0.30; 'modules,': 0.30; 'os,': 0.30; 'tjg': 0.30; 'moving': 0.31; 'list': 0.32; 'actual': 0.32; 'does': 0.32; 'anyone': 0.32; "what's": 0.33; "i've": 0.34; 'on,': 0.34; 'header :User-Agent:1': 0.34; 'hacking': 0.34; 'machine': 0.37; 'using': 0.37; 'several': 0.37; 'but': 0.37; 'back.': 0.38; 'showing': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'case': 0.39; 'skip:w 30': 0.61; 'below': 0.62; 'forward': 0.62; 'from:addr:mail': 0.64; 'restore': 0.64; 'minutes': 0.64; 'with,': 0.77; 'messed': 0.84; 'to:none': 0.93 Date: Tue, 23 Aug 2011 09:26:38 +0100 From: Tim Golden User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 CC: python-list@python.org Subject: Re: Setting the time in Win7 References: <2011082210352016807-bob@passcalnmtedu> <2011082213422850073-bob@passcalnmtedu> In-Reply-To: <2011082213422850073-bob@passcalnmtedu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314088002 news.xs4all.nl 23873 [2001:888:2000:d::a6]:42745 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12068 On 22/08/2011 20:42, Bob Greschke wrote: > Several people have been hacking away on this computer we are testing > on, so I'm not sure what settings -- other than all of them -- have been > messed with, but popen("time ...") seems to work, but system("time ...") > does not. I'm going to restore the machine to its original state and see > what happens. Hoping that this helps: you can programatically set the system time from within Python by using the pywin32 modules, or ctypes if you prefer. The code below works for an already-elevated command prompt by enabling the SystemTime privilege and (crudely) moving the time forward by five minutes by way of showing what's happening before resetting it back. I've commented out the actual SetSystemTime calls just in case anyone cuts-and-pastes indjudiciously. Ideally you should disable the privilege afterwards but I've left that out so as not to clutter the example. import os, sys import win32api import win32security import ntsecuritycon hToken = win32security.OpenProcessToken ( win32api.GetCurrentProcess (), ntsecuritycon.MAXIMUM_ALLOWED ) time_privilege = win32security.LookupPrivilegeValue (None, win32security.SE_SYSTEMTIME_NAME) win32security.AdjustTokenPrivileges ( hToken, 0, [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)] ) current_time = win32api.GetSystemTime () print "Current time:", current_time new_time = list (current_time) new_time[5] += 5 ## print win32api.SetSystemTime (*new_time) print "Current time:", win32api.GetSystemTime () ## print win32api.SetSystemTime (*current_time) print "Current time:", win32api.GetSystemTime () TJG