Programmatically Set the System Time in LabVIEW

Updated Sep 18, 2018

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full

Operating System

  • Windows

Issue Details

I am reading GPS time from an instrument and would like to set the Windows system time at a high resolution from LabVIEW. I've noticed the Get Time/Date VIs on the time palette in LabVIEW, but I cannot find any "set time" VIs.

Solution

There are no built in LabVIEW VIs to set the system time. However, this can be accomplished using the Windows SDK. Here are the instructions to use a Call Library Function Node to call the SetSystemTime function from the kernel32.dll:
  1. Place a Call Library Function Node on the block diagram. Double-click the node to open the Call Library Function dialog box.
  2. Click the Browse button and select the kernel32.dll (usually found at C:\WINDOWS\system32\kernel32.dll").
  3. Select SetSystemTime from the Function Name drop-down list.
  4. Select stdcall (WINAPI) from the Calling Conventions drop-down list.
  5. For Return Type select "Numeric" and select "Signed 8-bit Integer".
  6. Click Add a Parameter After and for Type select "Adapt to Type" and for Data Format select "Pointers to Handles".
  7. Click the OK button to configure the Call Library Function Node.
  8. This function takes a structure of eight WORDS (16-bit integers) as a parameter. To replicate this in LabVIEW, create a cluster of eight WORDS. The eight WORDS represent the Year, Month, Day of Week, Day of Month, Hour, Minute, Second, and Millisecond. Wire the cluster to the param 1 input of the Call Library Function Node.
  9. Enter the desired values and run the program to set the system time.
Note: If you are calling the SetSystemTime from LabVIEW in Windows Vista or Windows 7, you must run LabVIEW as an administrator. To do this, right-click the LabVIEW icon and select Run as administrator.

Additional Information

Refer to the SetSystemTime documentation on msdn.com for more information on this function. Note that a GetSystemTime function also exists in kernel32.dll.

For more information about configuring the Call Library Function Node in LabVIEW 7.1 or earlier, refer to the Using External Code in LabVIEW manual. In LabVIEW 8.0 or later, refer to the Configuring the Call Library Function Node topic in the LabVIEW Help for more information.

WAS THIS ARTICLE HELPFUL?

Not Helpful