Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tryng to Set local PC time from the server time

0 views
Skip to first unread message

Christine Zebarth

unread,
May 28, 1998, 3:00:00 AM5/28/98
to
I am trying to find a method of getting PC clocks in sych with the server.  Everytime a PowerBuilder application is launched,
I want the server time to write to the local PC clock.  The PowerBuilder Application that is being executed is 16 bit and is
running on Windows '95.  I tried to accomplish this by using the SetSystemTime function from Kernal32.dll.  I could receive
the servertime, but I could not write it to the PC clock.
In the code below, The "IF SetSystemTime(str_server) THEN" never returns a true value.
The code compiles without errors and doesn't give me a runtime error.

Here is the code that I use....

1.  The open event of my application object calls a function, in that function I have ...
 
    s_server_datetime str_server
    datetime ldt_server
    time  lt_server
    date  ld_server
 
    select getdate() into :ldt_server from Parm using SQLCA;
 
    IF SQLCA.SQLCODE = 0 THEN
        lt_server = time(ldt_server)
        ld_server = date(ldt_server)
        str_server.ll_day = day(ld_server)
        str_server.ll_month = month(ld_server)
        str_server.ll_year = year(ld_server)
        str_server.ll_hour = hour(lt_server)
        str_server.ll_minute = minute(lt_server)
        str_server.ll_second = second(lt_server)
        str_server.ll_millisecond = 00
        IF SetSystemTime(str_server) THEN
            MessageBox("Should Have Written: ", string(ldt_server))
        END IF
    END IF

2.  The structure contains....
 
    Variable Name      Type
        ll_day                 long
        ll_month             long
        ll_year                long
        ll_hour                long
        ll_minute             long
        ll_second            long
        ll_millisecond      long

3.  The Global External Function is declared as....

        FUNCTION boolean SetSystemTime(ref s_server_datetime systimeptr) Library "Kernal32.dll"
 

Please let me know if you have a better way of accomplishing this or if you know why my code isn't working...
 
 

BB

unread,
May 29, 1998, 3:00:00 AM5/29/98
to
I am using SetLocalTime() and calling it from within dll. And it works fine.
For Example :
 
int WINAPI MySetLocalTime(int year, int month, int day, int hour, int minute, int second)
{
SYSTEMTIME t;
 
t.wYear   = (WORD) year;
t.wMonth  = (WORD) month;
t.wDay    = (WORD) day;
t.wHour   = (WORD) hour;
t.wMinute = (WORD) minute;
t.wSecond = (WORD) second;
t.wMilliseconds = (WORD) 0;
 
return (int) SetLocalTime(&t);
}
Christine Zebarth wrote in message <356DDB34...@carey.cosd.fedex.com>...

BB

unread,
May 29, 1998, 3:00:00 AM5/29/98
to
Try to use SetLocalTime() from within the dll. For me it works.
Z.B.
Christine Zebarth wrote in message <356DDB34...@carey.cosd.fedex.com>...

Brian K. Galler

unread,
May 29, 1998, 3:00:00 AM5/29/98
to

If you are on a Novell network there is a network utility that can
synchronize the workstation time to the server time. I have seen it used in
login scripts to synchronize the time everytime a user logs on. You could
possibly just run the external program from PB. Sorry I don't remember the
name of the utility. It is something like SETTIME or SETDATE or something.

Brian

Christine Zebarth wrote in message
<356DDB34...@carey.cosd.fedex.com>...

BB

unread,
May 30, 1998, 3:00:00 AM5/30/98
to
For 16-bit applications running on Win95 you can write your own dll with the following functions:

#include <dos.h>

void WINAPI _export MySetTime(int hour, int min, int sec)

{

struct time t;

t.ti_hour = hour;

t.ti_min = min;

t.ti_sec = sec;

t.ti_hund = 0;

settime(&t);

}

 

void WINAPI _export MySetDate(int year, int month, int day)

{

struct date d;

d.da_year = year;

d.da_mon = month;

d.da_day = day;

setdate(&d);

}

Christine Zebarth wrote in message <356DDB34...@carey.cosd.fedex.com>...

Syed Irfan Ahmad

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

Your application must have system-time privilege (the SE_SYSTEMTIME_NAME
privilege) for this function to succeed. This privilege is disabled by
default. Use the AdjustTokenPrivileges( ) API function to enable the privilege
and again to disable it after the time has been set.


*Irfan

0 new messages