Forum Discussion

MichaelMcFarlan's avatar
MichaelMcFarlan
Contributor
14 years ago

aqDateTime.SetSystemDateTime not working with Windows 7

I just upgraded from Vista to Windows 7 (64bit) and now the function SetSyStemDateTime function is not working. The function doesn't set the time and always returns false. I'm running this on the Administrator account so that is not the problem. I tried using the example in the helpfile but that actually didn't run due to some errors with SetTimeElements, but even when I adjusted that SetSystemDateTime still didn't work.



function
SettingNewSystemDateTime()

{

  dt1=aqDateTime.SetDateTimeElements(2010, 6,
22, 10, 15, 12);

  dt2=aqDateTime.SetDateElements(2010, 6,
22);

  time=aqDateTime.SetTimeElements(10, 15, 12);

  // Setting new
system date and time


  aqDateTime.SetSystemDateTime(dt1);

  //
Setting new system date


  aqDateTime.SetSystemDateTime(dt2);

  //
Setting new system time


  aqDateTime.SetSystemDateTime(time);

}

8 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)


    Hi David,


     


    Let me quote Allen's reply:


    As for the first two appearances (aqDateTime.SetDateElements and aqDateTime.SetTimeElements), the behavior is correct: the dt2 and time1 variables of the Date type contain only the date and time portions respectively, and the lacking parts are initialized as a zero value (00:00:00 in the first case and 12/30/1899 (the "zero date") in the second one).


     


    As the aqDateTime object contains only the time in your case, the SetSystemDateTime method releases the date value. It doesn't know what date should be set.


     




  • Hi Michael,



    Make sure you run TestComplete with the administrator privileges (account with the administrator privileges is not the same as running a program as an administrator). For more information, refer to the Testing Applications With TestComplete Under Windows Vista and Later Operating Systems help topic.



    I tried using the example in the helpfile but that actually didn't run due to some errors with SetTimeElements
    Thank you for reporting the issue. We will make the necessary corrections. The correct version of the script should look like this:

    function SettingNewSystemDateTime()
     

    {


      dt1=aqDateTime.SetDateTimeElements(2010, 6, 22, 10, 15, 12);


      dt2=aqDateTime.SetDateElements(2010, 6, 22);


      time1=aqDateTime.SetTimeElements(10, 15, 12); //variable with the name time1 is used


      // Setting new system date and time


      aqDateTime.SetSystemDateTime(dt1);


      // Setting new system date


      aqDateTime.SetSystemDateTime(dt2);


      // Setting new system time


      aqDateTime.SetSystemDateTime(time1);


    }
  • Thanks for your reply. That solved my problem. I find it kind of odd
    that I never had to use "Run as admin" in Vista but as longs at it's
    working I'm happy.
  • florentinach's avatar
    florentinach
    Occasional Contributor
    Hello,


    I need to change only the date on my machine, but not the time. I've tried to use the aqDateTime.SetDateElements/aqDateTime.SetSystemDateTime, but i'm having some problems. Maybe you can help me.



    When i'm running the following code in TestComplete the function doesn't set the date or the time correctly. I tried to use the example in the helpfile:


    functionSettingNewSystemDateTime()


    {


      dt1=aqDateTime.SetDateTimeElements(2010, 6, 22, 10, 15, 12);


      dt2=aqDateTime.SetDateElements(2010, 6, 22);


      time=aqDateTime.SetTimeElements(10, 15, 12);


      // Setting new system date


      aqDateTime.SetSystemDateTime(dt2);


      // Setting new system time


      aqDateTime.SetSystemDateTime(time);


      // Setting new system date and time


      aqDateTime.SetSystemDateTime(dt1);


    }


    After dt2 is set the date/time shown on my computer is 22June2010 12:00AM.


    After time is set the date/time shown on my computer is 9:15AM 12/30/1899.


    After dt1 is set the date/time shown on my computer is 11:15AM 6/22/2010


    If i'm running this function


    functionSettingNewSystemDateTime()


    {


      dt1=aqDateTime.SetDateTimeElements(2010, 6, 22, 10, 15, 12);


      // Setting new system date and time


      aqDateTime.SetSystemDateTime(dt1);


    }


    the time shown on my computer is correct 10:15AM 6/22/2010


    Do i need to set something on  my machine? What do i do wrong?


    Thanks in advance

  • Hello Florentina,



    We have reproduced the behavior. We will investigate it and let you know our results.



    As an alternative, you can try using the following code to change the date and time:



      var SetDate = "6.22.2010";

      var SetTime = "10:15"

      var WshShell = new ActiveXObject("WScript.Shell");

      WshShell.Exec("cmd /c date " + SetDate);

      WshShell.Exec("cmd /c time " + SetTime);









  • florentinach's avatar
    florentinach
    Occasional Contributor

    Hi David,


    I'm waiting for your response why those functions are not working properly.
    Meanwhile I will use the functions that you gave me.


    Thanks a lot for your response,


    Florentina


  • Hello Florentina,





    Thank you for reporting the issue with aqDateTime.SetDateTimeElements, it will be fixed in one of the future versions of TestComplete.





    As for the first two appearances (aqDateTime.SetDateElements and aqDateTime.SetTimeElements), the behavior is correct: the dt2 and time1 variables of the Date type contain only the date and time portions respectively, and the lacking parts are initialized as a zero value (00:00:00 in the first case and 12/30/1899 (the "zero date") in the second one).


  • Hi, were these functions ever changed.  I am seeing the same behaviour in TestComplete 10, on Windows 7



    ie

      var newTime = aqDateTime.SetTimeElements(hh, mm, ss);

      aqDateTime.SetSystemDateTime(newTime);

    converts the system date to 12/30/1899