Jump to content

Can I go back some years using dos in AutoIt?


Recommended Posts

I need to travel back five years to the past... jokes appart, I need to set the system date 5 years ago to use a WinXP Software at work, but i don't know how do it.

I tried setting a command line in dos, but the command 'date' only sets the full date, not only the years. 

I did this, for example: 

$yearsago = "date 01/01/2016"
Run(@Comspec & " /c " & $yearsago)

This works, I can set 01/01/2016 for instance, but when I finish doing what I have to do I must set the actual date. Can anyone help me?

Link to comment
Share on other sites

I haven't tested this and I have the nasty bit remmed out but this should toggle your system clock as required. This was a bit of fun and is an adaptation of the help example for _Date_Time_SetSystemTime()

Just uncomment the last 4 lines.

; Delorean.au3 Toggle system year between now and five years ago
#include <Date.au3>

$tCur = _Date_Time_GetSystemTime() ; Get current system time
$sSysTime = _Date_Time_SystemTimeToDateTimeStr($tCur)  ; convert to mm/dd/yyyy hh:mm:ss
$iMon = Number(StringMid($sSysTime, 1, 2))
$iDay = Number(StringMid($sSysTime, 4, 2))
$iYear = Number(StringMid($sSysTime, 7, 4))
$iHour = Number(StringMid($sSysTime, 12, 2))
$iMin = Number(StringMid($sSysTime, 15, 2))
$iSec = Number(StringMid($sSysTime, 18, 2))
If $iYear < 2021 Then
  $iYear += 5 ; bring it back to the future
Else
  $iYear -= 5 ; engage flux capacitor
EndIf
$tNew = _Date_Time_EncodeSystemTime($iMon, $iDay, $iYear, $iHour, $iMin, $iSec)    ; m, d, y, h, min, s
;~ If Not _Date_Time_SetSystemTime($tNew) Then
;~   MsgBox($MB_SYSTEMMODAL, "Error", "System clock cannot be SET" & @CRLF & @CRLF & _WinAPI_GetLastErrorMessage())
;~   Exit
;~ EndIf

 

Edited by pseakins
typo

Phil Seakins

Link to comment
Share on other sites

On 1/5/2021 at 2:28 PM, Earthshine said:

This looks troublesome. Why would you have to set the time back In order to use a piece of software?

Of course for license reasons.... I guess.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Developers
1 hour ago, Earthshine said:

isn't that against forum rules?

Don't worry...  we ( MODs)  are following topics and will act when needed.
You can obviously also report the thread, but then please only when it is confirmed going against the rules as till now there is no evidence, hence you didn't see any action yet after your first report.

So having said all of this: halve of the posts in this thread are now off-topic, so please don't post unless it is on-topic and let us do our work. ;)  

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

On 1/5/2021 at 12:44 PM, lgkoliveira said:

the command 'date' only sets the full date, not only the years

Hmm this works for me (date in french format)

; set old
$dateold = @MDay & "/" & @Mon & "/" & @Year-5  ; 2021 - 5 = 2016
Run(@ComSpec & " /c " & "date " & $dateold, "", @SW_HIDE)

; back
$currentdate = @MDay & "/" & @Mon & "/" & @Year+5  ; 2016 + 5 = 2021
Run(@ComSpec & " /c " & "date " & $currentdate, "", @SW_HIDE)

 

Link to comment
Share on other sites

22 hours ago, mikell said:

Hmm this works for me (date in french format)

; set old
$dateold = @MDay & "/" & @Mon & "/" & @Year-5  ; 2021 - 5 = 2016
Run(@ComSpec & " /c " & "date " & $dateold, "", @SW_HIDE)

; back
$currentdate = @MDay & "/" & @Mon & "/" & @Year+5  ; 2016 + 5 = 2021
Run(@ComSpec & " /c " & "date " & $currentdate, "", @SW_HIDE)

 

This is very good, thanks again. I used another command line, just to sync with the time set in our server (for setting the actual time and date). I did this:

RunWait(@ComSpec & " /c " & 'net time /DOMAIN:MyDomain /SET /YES', "", @SW_HIDE)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...