Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DATETIME() problem.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00124841
Message ID:
00347823
Vues:
25
>How do you get the server time, using VFP6, if it was NT server?
The following will retrieve a time from the passed server and set your PC time to it. This only works from an NT machine (workstation or server).
* tcserver is the server to use for synchonization (i.e. \\PC1)
lparameter tcserver
declare integer NetRemoteTOD in netapi32 STRING@, INTEGER@
declare RtlMoveMemory IN WIN32API as CopyMemory STRING@, INTEGER, INTEGER
declare integer SetSystemTime in kernel32 STRING@
lcserver = strconv(strconv(tcserver,1),5)+chr(0)
lnptr = 0
lctimeofday = replicate(chr(0),48)
lcsystemtime = space(0)
nres = NetRemoteTOD(@lcserver,@lnptr)
local lnyear, lnmonth, lndayofweek, lnday, lnhour, lnminute, lnsecond, lnmillsecond
if nres = 0 then
	=CopyMemory(@lctimeofday, @lnptr, 48)
	lnyear = DWordtoNum(substr(lctimeofday,41,4))
	lnmonth = DWordtoNum(substr(lctimeofday,37,4))
	lndayofweek = DWordtoNum(substr(lctimeofday,45,4))
	lnday = DWordtoNum(substr(lctimeofday,33,4))
	lnhour = DWordtoNum(substr(lctimeofday,9,4))
	lnminute = DWordtoNum(substr(lctimeofday,13,4))
	lnsecond = DWordtoNum(substr(lctimeofday,17,4))
	lcsystemtime = NumtoWord(lnyear)+NumtoWord(lnmonth)+NumtoWord(lndayofweek)+NumtoWord(lnday)+ ;
		NumtoWord(lnhour)+NumtoWord(lnminute)+NumtoWord(lnsecond)+NumtoWord(0)
	nres = SetSystemTime(@lcsystemtime)
	return nres # 0
else
	? "Didn't work" + space(5) + transform(nres)
endif
return

function DwordToNum
lparameter tcDWORD
local ln0,ln1,ln2,ln3
ln0=asc(subs(tcDWORD,1,1))
ln1=asc(subs(tcDWORD,2,1)) * (256)
ln2=asc(subs(tcDWORD,3,1)) * (256^2)
ln3=asc(subs(tcDWORD,4,1)) * (256^3)
return ln3 + ln2 + ln1 + ln0

function NumtoWord
lparameter tnNum
lcresult = chr(0)+chr(0)
if tnNum < (2^15 - 1) then
	lcresult = chr(mod(tnNum,256))+chr(int(tnNum/256))
else
	* not a valid number for a WORD value
endif
return lcresult
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform