J'ai trouvé un petit code chez les "anglais" ... Peut-être utile !
Cette procédure calcule le temps depuis lequel la machine est allumé...
Attention : 49,7 jours maximum... Aux cas ou

Code : Tout sélectionner
; ------------------------------------------------------------------------
; Temps que l'ordinateur est allumé ! (Ou entre deux prise du temps)
; Maximum 49,7 jours... pour ceux qui oublierais d'économiser le courant !
; ------------------------------------
; by Mistrel » 14 Nov 2010 05:11 ( Pour complément d'infos voir :
; http://www.purebasic.fr/english/viewtopic.php?f=12&t=44310
; -------------------------------------------------------------------------------
; REMARQUES : Peux être intéressant pour qui veux contrôler le temps de travaille
; en continus d'une machine depuis sa mise en route et aussi d'utilisation
; d'un ou l'autre programme sur une machine définie.
; -------------------------------------------------------------------------------
; Evalué en millisecondes ...
;
#PDH_FMT_LARGE=$00000400
#PDH_FMT_1000=$00002000
;
Structure PDH_FMT_COUNTERVALUE
CStatus.l
dummy.l
StructureUnion
longValue.l
doubleValue.d
largeValue.q
*AnsiStringValue
*WideStringValue
EndStructureUnion
EndStructure
;
CompilerIf #PB_Compiler_Unicode
Prototype PdhVbAddCounter(hQuery, CounterPath.p-ascii, *hCounter)
CompilerElse
Prototype PdhVbAddCounter(hQuery, CounterPath.s, *hCounter)
CompilerEndIf
;
Prototype PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, *Value)
Prototype PdhCollectQueryData(hQuery)
Prototype PdhVbOpenQuery(*hQuery)
Prototype PdhCloseQuery(hQuery)
;
;/ Uptime is in milliseconds
;
Procedure GetSystemUptime()
Protected LibID.i
Protected Ptr.i
Protected PDHError.i
Protected hQuery.i
Protected hCounter.i
Protected ElapsedTime.PDH_FMT_COUNTERVALUE
Protected PdhVbOpenQuery.PdhVbOpenQuery
Protected PdhVbAddCounter.PdhVbAddCounter
Protected PdhGetFormattedCounterValue.PdhGetFormattedCounterValue
Protected PdhCollectQueryData.PdhCollectQueryData
Protected PdhCloseQuery.PdhCloseQuery
Protected ElapsedTimeQ.q
Protected ElapsedTime49.l ;/ Elapsed uptime only accurate up to 49.7 days
;
;/ This method is the most accurate but is only supported by Vista and above
Ptr=GetProcAddress_(GetModuleHandle_("Kernel32.dll"),"GetTickCount64")
If Ptr
ProcedureReturn CallFunctionFast(Ptr)
EndIf
;
LibID=OpenLibrary(#PB_Any,"pdh.dll")
If Not LibID
PDHError=#True
EndIf
;
If Not PDHError
PdhVbOpenQuery=GetFunction(LibID,"PdhVbOpenQuery")
PdhVbAddCounter=GetFunction(LibID,"PdhVbAddCounter")
PdhGetFormattedCounterValue=GetFunction(LibID,"PdhGetFormattedCounterValue")
PdhCollectQueryData=GetFunction(LibID,"PdhCollectQueryData")
PdhCloseQuery=GetFunction(LibID,"PdhCloseQuery")
EndIf
;
If Not PdhVbOpenQuery&PdhVbAddCounter&PdhGetFormattedCounterValue&PdhCollectQueryData&PdhCloseQuery
PDHError=#True
ProcedureReturn #False
EndIf
;
If Not PDHError And PdhVbOpenQuery(@hQuery)
PDHError=#True
EndIf
;
If Not PDHError And PdhVbAddCounter(hQuery,"\System\System Up Time",@hCounter)
PDHError=#True
EndIf
;
If Not PDHError And PdhCollectQueryData(hQuery)
PDHError=#True
EndIf
;
If Not PDHError And PdhGetFormattedCounterValue(hCounter,#PDH_FMT_LARGE|#PDH_FMT_1000,0,@ElapsedTime)
PDHError=#True
EndIf
;
If hQuery
PdhCloseQuery(hQuery)
EndIf
;
If LibID
CloseLibrary(LibID)
EndIf
;/ If the clock has been set backwards such that the uptime would be
;/ a negative value, the result will be "0"
ElapsedTimeQ.q=ElapsedTime\largeValue
;
Ptr=GetProcAddress_(GetModuleHandle_("Kernel32.dll"),"GetTickCount")
If Ptr
ElapsedTime49=CallFunctionFast(Ptr)
If ElapsedTime49>ElapsedTimeQ.q
ElapsedTimeQ.q=ElapsedTime49
EndIf
EndIf
ProcedureReturn ElapsedTimeQ.q
EndProcedure
S.f=(GetSystemUptime()/1000) ; Temps millisecondes convertis en secondes
Debug "Secondes Totale : "+Str(Int(S)) ; Affiche le Total des secondes
H=Int(S/3600)
Debug "Heures : "+Str(H) ; Nombre d'heures...
M=Int(S.f/60)-H*60
Debug "Minutes : "+Str(M) ; Nombre de minutes
; ---------------------------------
Pour qui ça intéresse

Et bonne fin d'année...
