Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a Delphi Win32 application with a specific local time?

I have a Delphi program that starts behaving wrong when run over midnight. To make a reproducable test case I have to change the local time of the system to something before midnight, run the program for some time, check for an error and switch back. While this can surely be done manually, I have problems to automate that for testing.

Are there any possibilities to give an application a special time when run whithout changing the system time? This can be from outside the program or even inside.

Although this might be a general Windows question I tagged it with Delphi as any solution working with Delphi is fine, while some with other programming environments are useless in this case.

like image 496
Uwe Raabe Avatar asked Nov 29 '13 08:11

Uwe Raabe


1 Answers

There is an existing tool for that called RunAsDate:

Description

RunAsDate is a small utility that allows you to run a program in the date and time that you specify. This utility doesn't change the current system date and time of your computer, but it only injects the date/time that you specify into the desired application. You can run multiple applications simultaneously, each application works with different date and time, while the real date/time of your system continues to run normally.

How does it work ?

RunAsDate intercepts the kernel API calls that returns the current date and time (GetSystemTime, GetLocalTime, GetSystemTimeAsFileTime), and replaces the current date/time with the date/time that you specify.

System Requirements

RunAsDate works under Windows 2000, Windows XP, Windows Server 2003, Windows Server 2008, Windows Vista, Windows 7, and Windows 8. Older versions of Windows are not supported. The is also x64 version available in a separated download, for using with x64 applications.

enter image description here

like image 96
Remko Avatar answered Oct 12 '22 22:10

Remko