473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Windows SetLocalTime

I am trying to set the system time on my Windows computer, but avoid
using the DOS command (date, time).

Does anyone know what parameter to pass to function SetLocalTime?

CSharp ref
http://groups.google.com/group/micro...fc37c6c9148961

Thanks a bunch,
P
>>import ctypes
import pywintypes
t = pywintypes.Time(time.time())
ctypes.windll.kernel32.SetLocalTime(t)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
ArgumentError: argument 1: exceptions.TypeError: Don't know how to
convert parameter 1
>>ctypes.windll.kernel32.SetLocalTime(ctypes.addre ssof(t))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: invalid type

Dec 14 '06 #1
4 3644
Podi wrote in news:11*********************@16g2000cwy.googlegrou ps.com
in comp.lang.python:
I am trying to set the system time on my Windows computer, but avoid
using the DOS command (date, time).

Does anyone know what parameter to pass to function SetLocalTime?
<url:http://msdn.microsoft.com/library/de...l=/library/en-
us/sysinfo/base/setlocaltime.asp>

Google will usually find the documentation of anything in the
Windows API however sometimes it also helps to add "msdn" to
your search as in:

<url:http://www.google.com/search?client=....mozilla%3Aen-
US%3Aofficial_s&hl=en&q=setlocaltime+msdn&btnG=Goo gle+Search>

Adding site:msdn.microsoft.com is even better (but alas more typing):

<url:http://www.google.com/search?hl=en&lr=&client=firefox-
a&rls=org.mozilla%3Aen-US%3Aofficial_s&q=setlocaltime+site%
3Amsdn.microsoft.com&btnG=Search>

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Dec 14 '06 #2
Yes, thank you.

I found the function SetLocalTime or SetSystemTime to set the time from
MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am
having trouble passing parameter to the functions in Python.

Rob Williscroft wrote:
>
Google will usually find the documentation of anything in the
Windows API however sometimes it also helps to add "msdn" to
your search as in:
Dec 14 '06 #3
Podi wrote in news:11**********************@j72g2000cwa.googlegr oups.com in
comp.lang.python:
Rob Williscroft wrote:
>>
Google will usually find the documentation of anything in the
Windows API however sometimes it also helps to add "msdn" to
your search as in:
Yes, thank you.

I found the function SetLocalTime or SetSystemTime to set the time from
MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am
having trouble passing parameter to the functions in Python.
Ok I see, you will probably need these 2 bits of the ctypes
documentation:

http://docs.python.org/lib/ctypes-st...es-unions.html
http://docs.python.org/lib/ctypes-pointers.html

From there on geting to this is farly straight forward:

from ctypes import *
from ctypes.wintypes import WORD

class SYSTEMTIME(Structure):
_fields_ = [
( 'wYear', WORD ),
( 'wMonth', WORD ),
( 'wDayOfWeek', WORD ),
( 'wDay', WORD ),
( 'wHour', WORD ),
( 'wMinute', WORD ),
( 'wSecond', WORD ),
( 'wMilliseconds', WORD ),
]

GetSystemTime = windll.kernel32.GetSystemTime

st = SYSTEMTIME()

GetSystemTime( pointer( st ) )

print st.wYear, st.wMonth, st.wDayOfWeek

A bit more digging into the docs will get to this:

prototype = WINFUNCTYPE( None, POINTER( SYSTEMTIME ) )
paramflags = (1, "lpSystemTime" ),
GetSystemTime = prototype(("GetSystemTime", windll.kernel32), paramflags )

st = SYSTEMTIME()
GetSystemTime( st )
print st.wYear, st.wMonth, st.wDayOfWeek

Which will give a much better error message if you try to
pass something other than a SYSTEMTIME, as well as wrapping
the argument in pointer for you.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Dec 14 '06 #4
Thank you. It works :-)
P

Rob Williscroft wrote:
Ok I see, you will probably need these 2 bits of the ctypes
documentation:

http://docs.python.org/lib/ctypes-st...es-unions.html
http://docs.python.org/lib/ctypes-pointers.html

From there on geting to this is farly straight forward:
Dec 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
0
by: Ken Varn | last post by:
I have an ASP.NET application that is attempting to set the local computer time using pinvoke on the Win32 SetLocalTime function. I keep getting Error 5 (Access Denied) whenever I try to make this...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
2
by: rdilipk | last post by:
I am posting at the end of this post some code that P/Invoke's SetSystemTime to set the local system time. This call fails -- i.e the time is not set and the API returns false. However calling...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.