Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12038 > unrolled thread
| Started by | Bob Greschke <bob@passcal.nmt.edu> |
|---|---|
| First post | 2011-08-22 10:35 -0600 |
| Last post | 2011-08-23 09:49 -0600 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.python
Setting the time in Win7 Bob Greschke <bob@passcal.nmt.edu> - 2011-08-22 10:35 -0600
Re: Setting the time in Win7 Tim Golden <mail@timgolden.me.uk> - 2011-08-22 18:41 +0100
Re: Setting the time in Win7 Bob Greschke <bob@passcal.nmt.edu> - 2011-08-22 12:46 -0600
Re: Setting the time in Win7 Bob Greschke <bob@passcal.nmt.edu> - 2011-08-22 13:42 -0600
Re: Setting the time in Win7 Tim Golden <mail@timgolden.me.uk> - 2011-08-23 09:26 +0100
Re: Setting the time in Win7 Bob Greschke <bob@passcal.nmt.edu> - 2011-08-23 09:49 -0600
| From | Bob Greschke <bob@passcal.nmt.edu> |
|---|---|
| Date | 2011-08-22 10:35 -0600 |
| Subject | Setting the time in Win7 |
| Message-ID | <2011082210352016807-bob@passcalnmtedu> |
Permissions! We're running in an account as an administrator (the only account on the laptops) and the program just calls system(time xxxx) and system(date xxxx) after reading it from a connected GPS receiver. I've fiddled with everything I could find in the registry and with the secpol.msc program and there doesn't seem to be any reason that it can't set the time, but it can't. Any ideas? Thanks! Bob
[toc] | [next] | [standalone]
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2011-08-22 18:41 +0100 |
| Message-ID | <mailman.324.1314034912.27778.python-list@python.org> |
| In reply to | #12038 |
If memory serves, you need to enable a specific privilege to set the time in Vista+. Just a moment... Have a look here: http://support.microsoft.com/kb/300022 and look for SeSystemtimePrivilege generally. Sorry; I'm a bit rushed at the moment. Feel free to post back if that isn't clear TJG On 22/08/2011 17:35, Bob Greschke wrote: > Permissions! > > We're running in an account as an administrator (the only account on the > laptops) and the program just calls system(time xxxx) and system(date > xxxx) after reading it from a connected GPS receiver. I've fiddled with > everything I could find in the registry and with the secpol.msc program > and there doesn't seem to be any reason that it can't set the time, but > it can't. Any ideas? > > Thanks! > > Bob >
[toc] | [prev] | [next] | [standalone]
| From | Bob Greschke <bob@passcal.nmt.edu> |
|---|---|
| Date | 2011-08-22 12:46 -0600 |
| Message-ID | <2011082212460475249-bob@passcalnmtedu> |
| In reply to | #12042 |
Hi! Yup. I've been from one end of that article to the other with no luck. It must be something to do with the shell that the system() call creates not having permission to set the time, but I can't figure out how to get around it. Just using the GUI the account where the user is running the program from has permission to set the time. On 2011-08-22 11:41:45 -0600, Tim Golden <mail@timgolden.me.uk> said: > If memory serves, you need to enable a specific privilege to > set the time in Vista+. Just a moment... > > Have a look here: > > http://support.microsoft.com/kb/300022 > > and look for SeSystemtimePrivilege generally. Sorry; I'm > a bit rushed at the moment. Feel free to post back if > that isn't clear > > TJG > > On 22/08/2011 17:35, Bob Greschke wrote: >> Permissions! >> >> We're running in an account as an administrator (the only account on the >> laptops) and the program just calls system(time xxxx) and system(date >> xxxx) after reading it from a connected GPS receiver. I've fiddled with >> everything I could find in the registry and with the secpol.msc program >> and there doesn't seem to be any reason that it can't set the time, but >> it can't. Any ideas? >> >> Thanks! >> >> Bob
[toc] | [prev] | [next] | [standalone]
| From | Bob Greschke <bob@passcal.nmt.edu> |
|---|---|
| Date | 2011-08-22 13:42 -0600 |
| Message-ID | <2011082213422850073-bob@passcalnmtedu> |
| In reply to | #12042 |
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.
Bob
On 2011-08-22 11:41:45 -0600, Tim Golden <mail@timgolden.me.uk> said:
> If memory serves, you need to enable a specific privilege to
> set the time in Vista+. Just a moment...
>
> Have a look here:
>
> http://support.microsoft.com/kb/300022
>
> and look for SeSystemtimePrivilege generally. Sorry; I'm
> a bit rushed at the moment. Feel free to post back if
> that isn't clear
>
> TJG
>
> On 22/08/2011 17:35, Bob Greschke wrote:
>> Permissions!
>>
>> We're running in an account as an administrator (the only account on the
>> laptops) and the program just calls system(time xxxx) and system(date
>> xxxx) after reading it from a connected GPS receiver. I've fiddled with
>> everything I could find in the registry and with the secpol.msc program
>> and there doesn't seem to be any reason that it can't set the time, but
>> it can't. Any ideas?
>>
>> Thanks!
>>
>> Bob
[toc] | [prev] | [next] | [standalone]
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2011-08-23 09:26 +0100 |
| Message-ID | <mailman.341.1314088002.27778.python-list@python.org> |
| In reply to | #12052 |
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.
<code>
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 ()
</code>
TJG
[toc] | [prev] | [next] | [standalone]
| From | Bob Greschke <bob@passcal.nmt.edu> |
|---|---|
| Date | 2011-08-23 09:49 -0600 |
| Message-ID | <2011082309493416807-bob@passcalnmtedu> |
| In reply to | #12068 |
On 2011-08-23 02:26:38 -0600, Tim Golden <mail@timgolden.me.uk> said:
> 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.
>
> <code>
> 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 ()
>
> </code>
>
> TJG
Oooo. Now I can be dangerous. We kinda also solved the whole thing
for us (just a few minutes ago) by checking the checkbutton "Run as
administrator" in the Properties, Compatibility tab, for python.exe and
pythonw.exe. The account is an Administrator, so it's OK for this.
I thought there must be a way through pywin32, but I don't know much of
anything about Windows API calls. I have a Windows Programming book
collecting dust somewhere...
Thanks!
Bob
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web