Change date and time of windows

Just starting out? Need help? Post your questions and find answers here.
PremierePRO
User
User
Posts: 28
Joined: Tue Apr 16, 2013 10:31 am

Change date and time of windows

Post by PremierePRO »

Hello
I could use a little program to change the date and system time , I used the following code

Code: Select all

Structure Time 
  Giorno.w
  Mese.w 
  Anno.w 
  Ora.w 
  Minuti.w 
  Secondi.w 
EndStructure

Dim SetTime.Time(1)
SetTime(1)\Giorno=25
SetTime(1)\Mese=12 
SetTime(1)\Anno=2015
SetTime(1)\Ora=23
SetTime(1)\Minuti=59
SetTime(1)\Secondi=59
but the date of windows does not change ...

where am I wrong ?

Thank you.

__________________________________________________
Code-Tags added
04.12.2015
RSBasic
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Change date and time of windows

Post by infratec »

Hi,

you only set some variables in a structured array.

Where is your command to set the system time :?: :?: :?:

Bernd
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Change date and time of windows

Post by ts-soft »

As Administrator:

Code: Select all

; enable admin-modus!
CompilerIf Defined(SYSTEMTIME, #PB_Structure) = 0
  Structure SYSTEMTIME
    wYear.w
    wMonth.w
    wDayOfWeek.w
    wDay.w
    wHour.w
    wMinute.w
    wSecond.w
    wMilliseconds.w
  EndStructure
CompilerEndIf

Define SetTime.SYSTEMTIME
SetTime\wDay = 25
SetTime\wMonth = 12
SetTime\wYear = 2015
SetTime\wHour = 23
SetTime\wMinute = 59
SetTime\wSecond = 59

SetLocalTime_(SetTime)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PremierePRO
User
User
Posts: 28
Joined: Tue Apr 16, 2013 10:31 am

Re: Change date and time of windows

Post by PremierePRO »

ts-soft wrote:As Administrator:

Code: Select all

; enable admin-modus!
CompilerIf Defined(SYSTEMTIME, #PB_Structure) = 0
  Structure SYSTEMTIME
    wYear.w
    wMonth.w
    wDayOfWeek.w
    wDay.w
    wHour.w
    wMinute.w
    wSecond.w
    wMilliseconds.w
  EndStructure
CompilerEndIf

Define SetTime.SYSTEMTIME
SetTime\wDay = 25
SetTime\wMonth = 12
SetTime\wYear = 2015
SetTime\wHour = 23
SetTime\wMinute = 59
SetTime\wSecond = 59

SetLocalTime_(SetTime)

I tried , but the time and date of windows do not change .... @:(
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Change date and time of windows

Post by ts-soft »

This is required:
Image
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Change date and time of windows

Post by infratec »

Hi,

have you really enabled Administrator mode in Compiler options?

This works here:

Code: Select all

CompilerIf Defined(SYSTEMTIME, #PB_Structure) = 0
  Structure SYSTEMTIME
    wYear.w
    wMonth.w
    wDayOfWeek.w
    wDay.w
    wHour.w
    wMinute.w
    wSecond.w
    wMilliseconds.w
  EndStructure
CompilerEndIf

Define SetTime.SYSTEMTIME
SetTime\wDay = 25
SetTime\wMonth = 12
SetTime\wYear = 2015
SetTime\wHour = 23
SetTime\wMinute = 59
SetTime\wSecond = 59

If SetLocalTime_(@SetTime) = 0
  Debug GetLastError_()
EndIf
If not you see now the error code.

Bernd
PremierePRO
User
User
Posts: 28
Joined: Tue Apr 16, 2013 10:31 am

Re: Change date and time of windows

Post by PremierePRO »

infratec wrote:Hi,

have you really enabled Administrator mode in Compiler options?

This works here:

Code: Select all

CompilerIf Defined(SYSTEMTIME, #PB_Structure) = 0
  Structure SYSTEMTIME
    wYear.w
    wMonth.w
    wDayOfWeek.w
    wDay.w
    wHour.w
    wMinute.w
    wSecond.w
    wMilliseconds.w
  EndStructure
CompilerEndIf

Define SetTime.SYSTEMTIME
SetTime\wDay = 25
SetTime\wMonth = 12
SetTime\wYear = 2015
SetTime\wHour = 23
SetTime\wMinute = 59
SetTime\wSecond = 59

If SetLocalTime_(@SetTime) = 0
  Debug GetLastError_()
EndIf
If not you see now the error code.

Bernd
OK.... :D

PS.



one last thing , if I wanted to add a loop ?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Change date and time of windows

Post by Dude »

PremierePRO wrote:if I wanted to add a loop ?
LOL, trying to bypass a time-limited app, eh? ;)
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Change date and time of windows

Post by infratec »

Are you really sure that you have already programmed before :mrgreen:

Loops in PB:

For Next
While Wend
Repeat Until

With a Delay() between.

Or, if you write a GUI program: AddWindowTimer()

Bernd
Post Reply