Hallo,
bisher war es unter clipper so, das der User das Systemdatum aus dem Programm heraus ändern konnte. Das wollte ich eigentlich bei Xbase beibehalten. Nur wie bekomme ich das richtig hin, das die Datumsfunktion von Windows gestartet wird.
Mit der control.exe kriege ich das hin, wo man Datum und Benutzerkonten ect. anspringen kann. Dabei muß ich aber den Pfad mit angeben. - Gibt es eine andere Lösung.?? Oder wie kriege ich den Pfad automatisch raus? Bisher habe ich den in einer Datenbank
eingetragen.
Systemdatum ändern
Moderator: Moderatoren
- Rolf Ramacher
- Der Entwickler von "Deep Thought"
- Beiträge: 1930
- Registriert: Do, 09. Nov 2006 10:33
- Wohnort: Bergheim
- Danksagung erhalten: 3 Mal
- Kontaktdaten:
- AUGE_OHR
- Marvin
- Beiträge: 12903
- Registriert: Do, 16. Mär 2006 7:55
- Wohnort: Hamburg
- Hat sich bedankt: 19 Mal
- Danksagung erhalten: 44 Mal
Re: Systemdatum ändern
hi,
eine "einfache" Lösung wärewomit das "übliche" Applet aufgerufen wird.
du kannst es aber auch üver die Win API machen :
eine "einfache" Lösung wäre
Code: Alles auswählen
IF OS( OS_FAMILY ) == "WINNT"
RUNSHELL( "Shell32,Control_RunDLL Timedate.cpl,@0,02", GETENV( "SYSTEMROOT" )+"\SYSTEM32\RUNDLL32.EXE", .T. )
ELSE
RUNSHELL( "Shell32,Control_RunDLL Timedate.cpl,@0,02", "C:\WINDOWS\RUNDLL32.EXE", .T. )
ENDIF
du kannst es aber auch üver die Win API machen :
Code: Alles auswählen
*******************************************************************************
*
* SetSystemTime.prg Ver.2.30 Greg Doran Copyright (c) 2001-2
*
* The Get/SetSystemTime function retrieves/sets the current
* System Date and Time.
*
* The System Time is expressed in Coordinated Universal Time (UTC) [GMT].
* In setting time the nDayOfWeek member of the SYSTEMTIME structure is ignored.
*
* Some, if not all, Operating Systems appear to apply a negative bias of
* 10 to 50 milliseconds to the SetSystemTime, and, also appear to ignore
* the milli-Second setting if it is already within a hysteris band of
* about +or- 30msec of the time being set.
*
*******************************************************************************
#include "xbp.ch"
#include "Appevent.ch"
#include "Gra.ch"
#include "common.ch"
#include "font.ch"
#include "dll.ch"
#include "dll.ch"
#ifndef CRLF
#define CRLF Chr(13)+Chr(10)
#define CRLF2 CRLF + CRLF
#endif
#ifndef gdBGN
#define gdBGN 31251676 // Background GraMakeRGBColor({220,220,220})
#define gdPYL 29949951 // Pastel Yellow GraMakeRGBColor({255,255,200})
#endif
***** APPSYS() added to make a 'main', remove when used
***** as 'Function SysDateandTime()'
FUNCTION APPSYS()
RETURN nil
****** Normally this is Function SysDateandTime()
FUNCTION main // SysDateandTime()
LOCAL oDlg, oDa, oXbp,oXbp1, oXbp2,oXbpT,oGB1,oXbpTD,oMsg
LOCAL aPos := {nil,nil}
LOCAL aSize := {330,205}
LOCAL mp1 := 0
LOCAL mp2 := 0
LOCAL nEvent := 0
LOCAL lExit := .F.
LOCAL aSleList := {} // Used to record all SLEs for :getData() eval.
LOCAL lHotSpot := .F. // Indicates if the cursor is over an SLE
LOCAL aTime := Array(8) // Holds the Date-Time variables
LOCAL cTBuffer := Space(16)// 'Type Structure' location for SystemTime
LOCAL cLocalTime := "" // Formatted Local Time
LOCAL cSystemTime := "" // Formatted System Time
*
*** CodeBlock Actions on SetSystemTime Button Activate.
*** ====================================================
*** Make sure all SLE data is transferred to the aTime array
*** Invoke the function that calls the SetSystemTime API
*** Read the new Local and System Time values.
*** Display the new Data and time values.
*** Indicate that TaskBar will update at seconds = 60.
*
LOCAL bSetGetUpdate:= ;
{|| aEval(aSleList, {|x,i| aTime[i]:= aSleList[i]:getData() }) ,;
SetTime(@cTBuffer, aTime),;
cLocalTime := GetLocTime( @cTBuffer ), ;
cSystemTime:= GetSysTime( @cTBuffer, @aTime),;
oXbpTD:setCaption("Time:"+Space(21)+"Date:"+;
CRLF+cLocalTime+CRLF+cSystemTime,;
oMsg:setCaption(;
"TaskBar time display will change at seconds = 60"),oMsg:show() )}
*
***** Create Dialog, No max,min or tasklist
*
aPos[1] := (AppDeskTop():currentSize()[1]- aSize[1]) / 2
aPos[2] := (AppDeskTop():currentSize()[2]- aSize[2]) / 2
oDlg := XbpDialog():new( , , aPos, aSize, , .T.)
oDlg:title := "System Date & Time - "+;
"Copyright (c) 2001/2 GJDoran"
oDlg:taskList := .F.
oDlg:sysmenu := .F.
oDlg:titleBar := .T.
oDlg:alwaysontop := .T.
oDlg:visible := .T.
oDlg:maxsize := aSize
oDlg:close := {|| lExit:= .T. }
oDlg:drawingArea:setColorFG( GRA_CLR_BLACK )
oDlg:drawingArea:setColorBG( gdBGN )
oDlg:create()
oDa:= oDlg:drawingarea
SetAppWindow(oDlg)
setAppFocus(oDlg)
***** Get the Local Time
*
cLocalTime := GetLocTime( @cTBuffer )
***** Get the System Time
*
cSystemTime := GetSysTime( @cTBuffer, @aTime)
***** Display the Times
*
oGB1:= XbpStatic():new(oDa,, {20,90}, {285, 90})
oGB1:Type := XBPSTATIC_TYPE_GROUPBOX
oGB1:caption := ""
oGB1:setColorBG( GRA_CLR_WHITE )
oGB1:create()
oXbp:= XbpStatic():new(oGB1,, {18,10}, {85, 62})
oXbp:options := XBPSTATIC_TEXT_LEFT+XBPSTATIC_TEXT_WORDBREAK
oXbp:caption := "Source:"+CRLF+"API Local "+CRLF+"API System"
oXbp:setColorFG( GRA_CLR_BLACK )
oXbp:setColorBG( gdBGN )
oXbp:create()
oXbp:setFontCompoundName( "9.Arial" )
oXbpTD:= XbpStatic():new(oGB1,, {106,10}, {165, 62})
oXbpTD:options := XBPSTATIC_TEXT_LEFT+XBPSTATIC_TEXT_WORDBREAK
oXbpTD:caption := "Time:"+Space(21)+"Date:"+CRLF+cLocalTime+CRLF+cSystemTime
oXbpTD:setColorFG( GRA_CLR_BLACK )
oXbpTD:setColorBG( gdBGN )
oXbpTD:create()
oXbpTD:setFontCompoundName( "9.Arial" )
***** Show the Local Time() updated every second
***** and kill the '60 second' message if active.
*
oXbpT:= XbpStatic():new(oGB1,, {18, 7}, {250, 15})
oXbpT:options := XBPSTATIC_TEXT_CENTER
oXbpT:caption := "Local time is now"
oXbpT:setColorFG( GRA_CLR_BLUE )
oXbpT:setColorBG( gdBGN )
oXbpT:create()
oXbpT:setFontCompoundName( "9.Arial" )
SetTimerEvent(100, {|| oXbpT:setcaption("Local time is now: "+Time()),;
IIF(Right(Time(),2)=="00".AND."60"$oMsg:caption,oMsg:hide(),nil)} )
***** Create a General Message line.
*
oMsg:= XbpStatic():new(oDa,, {20, 29}, {285, 13},,.F.)
oMsg:options := XBPSTATIC_TEXT_CENTER+XBPSTATIC_TEXT_VCENTER
oMsg:caption := ""
oMsg:setColorFG( GRA_CLR_BLACK )
oMsg:setColorBG( gdPYL )
oMsg:create()
oMsg:setFontCompoundName( "8.Arial" )
***** Create a Heading for Date and Time SLEs
*
oXbp:= XbpStatic():new(oDa,, {25, 65}, {300, 20})
oXbp:options := XBPSTATIC_TEXT_LEFT+XBPSTATIC_TEXT_BOTTOM
oXbp:caption := "Year Month Day "+;
"Hour Min. Sec. mSec."
oXbp:setColorFG( GRA_CLR_BLUE )
oXbp:setColorBG( gdBGN )
oXbp:create()
oXbp:setFontCompoundName( "9.Arial" )
***** Create a 'home' for the SLEs
*
oXbp1:= XbpStatic():new(oDa,, {20, 45}, {350, 20})
oXbp1:options := XBPSTATIC_TEXT_LEFT+XBPSTATIC_TEXT_BOTTOM
oXbp1:caption := ""
oXbp1:setColorFG( GRA_CLR_RED )
oXbp1:setColorBG( gdBGN )
oXbp1:create()
oXbp1:setFontCompoundName( "9.Arial Bold" )
***** Now house them on oXbp1 street....
*
***** Year
oXbp := XbpSLE():new(oXbp1 , , {0,0}, {35,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 4
oXbp:dataLink := {|x| IIf( x==NIL, aTime[1], aTime[1] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[1]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Date: Enter the current Year at Greenwich")}
***** Month
oXbp := XbpSLE():new(oXbp1 , , {52,0}, {20,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[2], aTime[2] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[2]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Date: Enter the current Month at Greenwich")}
***** This DayOfWeek item is hidden: it cannot be set.
***** It is here just to 'complete' the aSleList array set.
***** DayOfWeek
oXbp := XbpSLE():new(oXbp1 , , {72,0}, {20,18},,.F. )
oXbp:tabStop := .F.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[3], aTime[3] := x ) }
oXbp:create()
oXbp:setData()
aadd(aSleList,oXbp)
***** Day
oXbp := XbpSLE():new(oXbp1 , , {90,0}, {20,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[4], aTime[4] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[4]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Date: Enter the current Day at Greenwich")}
***** Hour
oXbp := XbpSLE():new(oXbp1 , , {135,0}, {20,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[5], aTime[5] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[5]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Time: Enter the current Hour G.M.T. [UTC]")}
***** Minute
oXbp := XbpSLE():new(oXbp1 , , {175,0}, {20,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[6], aTime[6] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[6]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Time: Enter the current Minute G.M.T. [UTC]")}
***** Second
oXbp := XbpSLE():new(oXbp1 , , {215,0}, {20,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 2
oXbp:dataLink := {|x| IIf( x==NIL, aTime[7], aTime[7] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[7]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"System Time: Enter the current Second G.M.T. [UTC]")}
***** mSecond
oXbp := XbpSLE():new(oXbp1 , , {255,0}, {30,18} )
oXbp:tabStop := .T.
oXbp:bufferLength := 3
oXbp:dataLink := {|x| IIf( x==NIL, aTime[8], aTime[8] := x ) }
oXbp:create()
oXbp:setData()
oXbp:killInputFocus := { |x,y,oSLE| aTime[8]:=oSLE:getData() }
aadd(aSleList,oXbp)
oXbp:motion := {|MP1,Mp2, o| SysTDmsg(o,MP1,@lHotspot,oMsg,;
"The OS may have a negative bias of 10 to 50 mSeconds")}
***** Create PushButtons
*
oXbp := XbpPushbutton():new(oDa,,{35,5}, {120,20} )
oXbp:caption := "Set Date and Time"
oXbp:activate := bSetGetUpdate
oXbp:TabStop := .T.
oXbp:create()
oXbp:setFontCompoundName( "9.Arial" )
oXbp := XbpPushbutton():new(oDa,,{171,5}, {120,20} )
oXbp:caption := "Exit Setup"
oXbp:activate := {|| lExit:= .T. }
oXbp:TabStop := .T.
oXbp:create()
oXbp:setFontCompoundName( "9.Arial" )
DO WHILE !(lExit)
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:handleEvent( nEvent, mp1, mp2 )
ENDDO
SetTimerEvent(0)
oDlg:destroy()
RETURN nil
*
* END FUNCTION main // SysDateandTime()
******************************************************************************
*
*******************************************************************************
* FUNCTION GetLocTime()
*
* A pointer to a string of 16 bytes cTBuffer is passsed to GetLocTime()
* GetLocTime returns a formatted string of Local Date and Time.
*
* A pointer to a string means: cTBuffer is passed by reference in the
* calling function e.g. GetLocTime(@cTBuffer)
*
********************************************************************************
FUNCTION GetLocTime( cTBuffer )
LOCAL cLocalTime := ""
LOCAL nYear := 0 // 2 Bytes (Int)
LOCAL nMonth := 0 // 2 Bytes (Int)
LOCAL nDayOfWeek := 0 // 2 Bytes (Int)
LOCAL nDay := 0 // 2 Bytes (Int)
LOCAL nHour := 0 // 2 Bytes (Int)
LOCAL nMinute := 0 // 2 Bytes (Int)
LOCAL nSecond := 0 // 2 Bytes (Int)
LOCAL nMilliseconds := 0 // 2 Bytes (Int)
DllCall("Kernel32.DLL", DLL_STDCALL, "GetLocalTime", @cTBuffer)
nYear := Bin2i( SubStr( cTBuffer, 1, 2 ))
nMonth := Bin2i( SubStr( cTBuffer, 3, 2 ))
nDayOfWeek := Bin2i( SubStr( cTBuffer, 5, 2 ))
nDay := Bin2i( SubStr( cTBuffer, 7, 2 ))
nHour := Bin2i( SubStr( cTBuffer, 9, 2 ))
nMinute := Bin2i( SubStr( cTBuffer, 11, 2 ))
nSecond := Bin2i( SubStr( cTBuffer, 13, 2 ))
nMilliseconds := Bin2i( SubStr( cTBuffer, 15, 2 ))
cLocalTime:=;
StrZero( nHour , 2 )+":"+;
StrZero( nMinute , 2 )+":"+;
StrZero( nSecond , 2 )+":"+;
StrZero( nMilliseconds , 3 )+Space(7)+;
StrZero( nYear , 4 )+"-"+;
StrZero( nMonth , 2 )+"-"+;
StrZero( nDay , 2 )
RETURN cLocalTime
* END FUNCTION GetLocTime()
*******************************************************************************
*
*******************************************************************************
* FUNCTION GetSysTime()
*
* A pointer to a string of 16 bytes cTBuffer is passsed to GetSysTime()
* along with this the array aTime is also passed to take on the returned
* values which will be loaded into the respective SLEs by :datalink.
*
* GetSysTime returns a formatted string of System Date and Time.
*
********************************************************************************
FUNCTION GetSysTime( cTBuffer, aTime )
LOCAL cSystemTime := ""
LOCAL nYear := 0 // 2 Bytes (Int)
LOCAL nMonth := 0 // 2 Bytes (Int)
LOCAL nDayOfWeek := 0 // 2 Bytes (Int)
LOCAL nDay := 0 // 2 Bytes (Int)
LOCAL nHour := 0 // 2 Bytes (Int)
LOCAL nMinute := 0 // 2 Bytes (Int)
LOCAL nSecond := 0 // 2 Bytes (Int)
LOCAL nMilliseconds := 0 // 2 Bytes (Int)
DllCall("Kernel32.DLL", DLL_STDCALL, "GetSystemTime", @cTBuffer)
nYear := Bin2i( SubStr( cTBuffer, 1, 2 ))
nMonth := Bin2i( SubStr( cTBuffer, 3, 2 ))
nDayOfWeek := Bin2i( SubStr( cTBuffer, 5, 2 ))
nDay := Bin2i( SubStr( cTBuffer, 7, 2 ))
nHour := Bin2i( SubStr( cTBuffer, 9, 2 ))
nMinute := Bin2i( SubStr( cTBuffer, 11, 2 ))
nSecond := Bin2i( SubStr( cTBuffer, 13, 2 ))
nMilliseconds := Bin2i( SubStr( cTBuffer, 15, 2 ))
aTime[1]:=StrZero( nYear , 4 )
aTime[2]:=StrZero( nMonth , 2 )
aTime[3]:=StrZero( nDayOfWeek , 1 )
aTime[4]:=StrZero( nDay , 2 )
aTime[5]:=StrZero( nHour , 2 )
aTime[6]:=StrZero( nMinute , 2 )
aTime[7]:=StrZero( nSecond , 2 )
aTime[8]:=StrZero( nMilliseconds , 3 )
cSystemTime:=;
StrZero( nHour , 2 )+":"+;
StrZero( nMinute , 2 )+":"+;
StrZero( nSecond , 2 )+":"+;
StrZero( nMilliseconds , 3 )+Space(7)+;
StrZero( nYear , 4 )+"-"+;
StrZero( nMonth , 2 )+"-"+;
StrZero( nDay , 2 )
RETURN cSystemTime
* END FUNCTION GetSysTime()
*******************************************************************************
*
*******************************************************************************
* FUNCTION SetTime()
*
* A pointer to a string of 16 bytes cTBuffer is passsed to SetTime()
* along with the contents of the SLEs in the array aTime.
*
* SetTime() returns nil.
*
* (There is no such API as SetLocalTime(), only SetSystemTime())
*
********************************************************************************
FUNCTION SetTime( cTBuffer, aTime )
cTBuffer:= ;
i2Bin( Val(aTime[1] )) +;
i2Bin( Val(aTime[2] )) +;
i2Bin( Val(aTime[3] )) +;
i2Bin( Val(aTime[4] )) +;
i2Bin( Val(aTime[5] )) +;
i2Bin( Val(aTime[6] )) +;
i2Bin( Val(aTime[7] )) +;
i2Bin( Val(aTime[8] ))
DllCall("Kernel32.DLL", DLL_STDCALL, "SetSystemTime", @cTBuffer)
RETURN nil
* END FUNCTION SetTime()
*******************************************************************************
*
*******************************************************************************
* FUNCTION SysTDmsg()
*
* SysTDmsg() [System-Time-Date-message()] is used to sense when the mouse
* is over an SLE and results in a message appropriate to the SLE.
*
********************************************************************************
FUNCTION SysTDmsg(o,aP,lHotSpot,oMsg,cTxt)
LOCAL aSz := o:currentSize()
IF (aP[1] > 0 .AND. aP[1] < aSz[1] .AND. ;
aP[2] > 0 .AND. aP[2] < aSz[2])
IF ! lHotSpot
oMsg:setCaption(cTxt)
oMsg:show()
o:captureMouse( .T. )
lHotSpot := .T.
ENDIF
ELSE
IF lHotSpot
o:captureMouse( .F. )
lHotSpot := .F.
oMsg:hide()
ENDIF
ENDIF
RETURN nil
* END FUNCTION SysTDmsg()
*************************************************************************
gruss by OHR
Jimmy
Jimmy
- Rolf Ramacher
- Der Entwickler von "Deep Thought"
- Beiträge: 1930
- Registriert: Do, 09. Nov 2006 10:33
- Wohnort: Bergheim
- Danksagung erhalten: 3 Mal
- Kontaktdaten:
Re: Systemdatum ändern
Hi Jimmy,
ich habe den Aufruf ohne Abfrage getestet - mit Verzeichnis c:\windows\system32 - klappt das
aber mit deiner Abfrage erhalten ich eine Fehlermeldung das er OS_FAMILY nicht kennt- Laut Hilfe sieht es auch gleich aus, zumal
von einer CH die included werden muß steht da nichts. ???
Halt - Kommando zurück. Es ist die Os.Ch . wer lesen kann ist klar im Vorteil
ich habe den Aufruf ohne Abfrage getestet - mit Verzeichnis c:\windows\system32 - klappt das
aber mit deiner Abfrage erhalten ich eine Fehlermeldung das er OS_FAMILY nicht kennt- Laut Hilfe sieht es auch gleich aus, zumal
von einer CH die included werden muß steht da nichts. ???
Halt - Kommando zurück. Es ist die Os.Ch . wer lesen kann ist klar im Vorteil
- brandelh
- Foren-Moderator
- Beiträge: 15689
- Registriert: Mo, 23. Jan 2006 20:54
- Wohnort: Germersheim
- Hat sich bedankt: 65 Mal
- Danksagung erhalten: 33 Mal
- Kontaktdaten:
Re: Systemdatum ändern
Hi,
zu beachten ist auch, dass der User für das "normale" Ändern der Zeit mindestens "Hauptbenutzer" sein muss.
zu beachten ist auch, dass der User für das "normale" Ändern der Zeit mindestens "Hauptbenutzer" sein muss.
Gruß
Hubert
Hubert