LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set Windows Time Zone

I am trying to write a VI that will set the system time zone (in Windows). The user needs to be given the option to pick which time zone they are in. Then whatever changes are needed, must be written back out to Windows.

I want Windows to handle all the offsets and setting the local time. I just want to provide a way that the user can view a list of all the different time zones and pick one to set the local time by.

I have tried a couple different ways:

1. Calling the GetTimeZoneInformation in the kernel32.dll through the Call Library Function vi. However, I am not sure what input to give the node. I found documentation on:
http://msdn2.microsoft.com/en-us/library/ms724944.aspx
The issue arises when I attempt to create a cluster to match a TIME_ZONE_INFORMATION structure:
http://msdn2.microsoft.com/en-us/library/ms725481.aspx
I am having a very hard time figured out what data type WCHAR would be in my LabVIEW cluster.

2. Modifying the registry values at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
The problem arises that even if I set the StandardName and DaylightName, the time zone settings have not changed when I go to check them in the system clock and the local time has not been altered to reflect any time zone change. All the possible time zones are located at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
I have been able to determine that the data in the TZI subkey is structured as:

long Bias;
long StandardBias;
long DaylightBias;
SYSTEMTIME StandardDate;
SYSTEMTIME DaylightDate;

SYSTEMTIME is another structure that is made up of eight words:
http://msdn2.microsoft.com/en-us/library/ms724950.aspx
The information contained in the TZI tag can entered into the subkeys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation but I cannot figure out how to get the information in hex from that TZI tag into LabVIEW, divide it up and feed it back out.

If there is some other (hopefull easier) way to do this or if you can help me with either of the two ways I have already tried, I would greatly appreciate it. Please note that I cannot use any other tools that are not built-in to windows. So G-tools is out of the question.

Kyle

0 Kudos
Message 1 of 9
(5,577 Views)
I've gotta ask: why would you want to have an application set the system's time zone? It should be the other way around: an application should work with whatever time zone is set, since this affects the computer's operation. Do you reset the time zone after the application is finished? What happens if it crashes, or worse, if you don't reset it, and someone uninstalls the application, only to be left with the wrong time zone?
0 Kudos
Message 2 of 9
(5,564 Views)

That is a very good point.


The user needs to be given the option to pick which time zone they are in.

They already have that option. You double click the clock at the bottom of the screen and go into the Time Zone tab.
Why try to work around that just for the sake of your application?

I understand the need to try to make things easier for the users, but there is some point at which you should say no.

As for the actual question, I believe that WChar is a Unicode string (2 bytes for each character), so you need to allocation 2n bytes (an array of U8) and have the first byte of each pair be 0. There is a VI called by the registery VIs which does this conversion for you (it's called STR_ASCII-Unicode.vi).

In any case, if you must do this from your application, I suggest you simply call the date/time dialog.

One way would be to run the System Exec VI with "rundll32.exe shell32.dll,Control_RunDLL timedate.cpl" as the input, but there are probably other ways.


___________________
Try to take over the world!
0 Kudos
Message 3 of 9
(5,547 Views)
The issue arises that I don't even plan on running the explorer service of Windows. The LabVIEW application will be all the user ever sees, so just clicking the system clock and going to the time zone tab will not work. If it comes down to it, I could see how just calling the timedate.cpl might be the way to go, but I don't want to resort to that just yet.
 
Thank you for the information on the WCHAR
0 Kudos
Message 4 of 9
(5,537 Views)

Setting the time zone is a system-wide operation which ideally should be performed only once.

Would it really be that critical to have it as part of your application?
Why not just boot up once into the Windows shell and set everything that needs setting as part of the installation process?


___________________
Try to take over the world!
0 Kudos
Message 5 of 9
(5,523 Views)
Hi Kyle,

It looks like this example has an answer for you. The top level VI, TimeZone_Example.vi refers to the time zone in the StandardTime and DaylightName controls.

http://zone.ni.com/devzone/cda/epd/p/id/18

To change the time settings it uses c:\windows\system32\kernel32.dll in "SetTimeZoneInformationWrapper.vi". It uses the "SetTimeZoneInformation" function of kernel32.dll. To the left of the call library function node, you can see the how the time zone information is unbundled by name and you can see the StandardDate and DaylightDate.

Trey B
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 6 of 9
(5,515 Views)
One warning:

I believe the timezone is only read during initalization of LabVIEW

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 7 of 9
(5,493 Views)


@TonP wrote:

I believe the timezone is only read during initalization of LabVIEW

Good point. I forgot about that one.

I haven't checked it recently, but I assume that still happens in the newer versions.


___________________
Try to take over the world!
0 Kudos
Message 8 of 9
(5,481 Views)
I don't have any problem reading the time zone. It is setting the time zone and making the changes appear in the time zone properties when I check in the control panel.
 
Thank you for the example Trey...that was a big help. Think we will end up using that rather than struggling with changing the registry one value at a time!
 
Kyle
0 Kudos
Message 9 of 9
(5,467 Views)