473,856 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SetLo calTime(t)
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
ArgumentError: argument 1: exceptions.Type Error: Don't know how to
convert parameter 1
>>ctypes.windll .kernel32.SetLo calTime(ctypes. addressof(t))
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: invalid type

Dec 14 '06 #1
4 3676
Podi wrote in news:11******** *************@1 6g2000cwy.googl egroups.com
in comp.lang.pytho n:
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.as p>

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=setloc altime+msdn&btn G=Google+Search >

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

<url:http://www.google.com/search?hl=en&lr=&client=firefox-
a&rls=org.mozil la%3Aen-US%3Aofficial_s &q=setlocaltime +site%
3Amsdn.microsof t.com&btnG=Sear ch>

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.goo glegroups.com in
comp.lang.pytho n:
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(Stru cture):
_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, "lpSystemTi me" ),
GetSystemTime = prototype(("Get SystemTime", 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
15238
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 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
1
3457
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 going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
0
3947
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 - Select from two specific services - Check the status of the server
4
3165
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 further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
0
1083
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 call. I have attempted to impersonate a reserved user that I have given Administrator rights, but the call still seems to be failing. I have even tried setting the access token to enable SE_SYSTEM_NAME privilige, but still no luck. Can...
2
11736
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 another CD, and gets caught in a loop when I try to delete it! It mentions MS.net frame error # 1706. The "details" code follows...hope someone can help me to either fix it or get out of the loop! I tried running "Windows Registry Repair Pro"...but no help...
1
7861
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 am note sure what to do because all propertiers work, except the System.Data.DataColumn.. I didn't write any code by hand and used the visual studio to set the properties..
2
8427
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 Marshal.GetLastWin32Error immediately afterwards returns an errorcode of 0 indicating that the operation somehow executed successfully. This is a plain vanilla console app written in C#. It runs on vista and has a manifest embedded in it that...
0
9916
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9762
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11056
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10696
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10782
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7093
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.