In my VB6 program I need to check few times per hour user has correct date/time on his station,

Posted on 2008-11-07
Last Modified: 2012-05-11
in a VB program I must be sure user has correct date and time while entering data, can  I "ping" some Internet site and take there correct date/time few times per hour and if needed update systemclock in Xp machine?
Question by:BIAPRO
    LVL 8

    Expert Comment

    an ugly. but  working way is

    VB6 has a function called Shell which Runs an executable program and returns an integer containing the program's process ID if it is still running.

    Write a temporary file (tempfile.txt) that contains the time command

    time 10:01

    then run the shell function

    shell ("cmd.exe < tempfile.txt")
    LVL 11

    Expert Comment

    API Method from AllAPI:

    Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
    End Type
    Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
    Private Sub Form_Load()
        Dim lpSystemTime As SYSTEMTIME
        lpSystemTime.wYear = 2000
        lpSystemTime.wMonth = 1
        lpSystemTime.wDayOfWeek = -1
        lpSystemTime.wDay = 24
        lpSystemTime.wHour = 23
        lpSystemTime.wMinute = 26
        lpSystemTime.wSecond = 0
        lpSystemTime.wMilliseconds = 0
        'set the new time
        SetSystemTime lpSystemTime
    End Sub
    LVL 11

    Accepted Solution

    My apologies BIAPRO, I misread your question and took it that you already had a method for getting the time from a server and just wanted a method for setting the system clock from that.

    Check out this simple VB project download which uses a WinSock control to retrieve the server time. You should be able to adapt the code therein to your own needs.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now