Changing system time

Class library usage, coding and language questions.
User avatar
Naplespoet
Certified Professional
Certified Professional
Posts: 9
Joined: Fri May 20, 2016 6:12 am

Changing system time

Post by Naplespoet » Tue Jan 17, 2017 7:50 pm

Is there a way to change system time on the machine that is being tested.

I have an app that says ok this value is 10 for example
In 2 hours it will be 20
3 hours ago it should have been 2 . (this is just an example)

the app looks at system time on the machine the test is running on.

is there a way to set the local machines time through code ? if so please help.

User avatar
Naplespoet
Certified Professional
Certified Professional
Posts: 9
Joined: Fri May 20, 2016 6:12 am

Re: Changing system time

Post by Naplespoet » Tue Jan 17, 2017 8:46 pm

yay found some code to help just change the time now i have to figure out a function to grab current time set it minus an hour or whatever amount of time i need forward or backwards


public void setTime(string timeInYourSystemFormat)
{
var proc = new System.Diagnostics.ProcessStartInfo();
proc.UseShellExecute = true;
proc.WorkingDirectory = @"C:\Windows\System32";
proc.CreateNoWindow = true;
proc.FileName = @"C:\Windows\System32\cmd.exe";
proc.Verb = "runas";
proc.Arguments = "/C time " + timeInYourSystemFormat;
try
{
System.Diagnostics.Process.Start(proc);
}
catch
{
Report.Log(ReportLevel.Failure,"Time was not changed");
}
}