setting system time :: vugen

Quite often I get personally contacted by people requiring some assistance or just wanting to ask me for my advice. It’s a nice ego boost, but also a very important aspect of the industry that should be maintained. My beliefs are we should do what we can to assist others, and with the use of the internet, we have a great medium to share and distribute information, with such things like twitter, Google talk and, well my blog, are all making it possible for a total stranger to speak to another and get the help he/she needs.

Recently, a now friend of mine, Roberto Brusa struck up a conversation about changing the system time in vugen. He was making a system call, which is fine, its a great way to do it, but he did mention that he did not want the annoying cmd pop up and probed me for a possible alternative. Now I’ve never done this before but after bouncing ideas off each other I suggested that in theory, it should be possible, through the usage of the win32api, to manipulate the tme…We found that this statment was true, and proved it with the following…

Not many performance testers know about this little trick, but I have used it a few times. its the lr_load_dll() function. It allows you to load a dll into your vuser_init(), and once loaded, you can call any function that is inside that dll anytime in your script.
The hardest part, is finding out what the dll does, what functions can be called, and the format in which they must be placed. A quick Google search should solve your issues, or jump on the msdn.

Now, the kernel32.dll is responsible for setting the system time, as well as many other things, and explicitly calling SetSystemTime allows full manipulation. With this information and some intuitive Google searching from Roberto and I, collectively we managed to come up with this script, which sets the system time to whatever you want, right down to the millisecond!.

vuser init
note: I declare all my variables before the vuser_init function, for neatness.

double atof (const char *string);
typedef struct _SYSTEMTIME {
  WORD wYear;
  WORD wMonth;
  WORD wDayOfWeek;
  WORD wDay;
  WORD wHour;
  WORD wMinute;
  WORD wSecond;
  WORD wMilliseconds;
   return 0;

Set your values, and call the function…

   st.wYear = 2000;
   st.wMonth = 5;
   st.wDay = 12;
   st.wHour = 16;
   st.wMinute = 8;
   st.wSecond = 31;
   st.wMilliseconds = 55;
   //call the function for the dll, parsing the input value of st paramater
   return 0;

Use it at your will!


  • Roberto Brusa
    November 6, 2009 - 1:52 am | Permalink

    … an add-on, maybe useful:

    if you want to take care of your local time zone instead of GMT, you should use


  • mrearnest
    June 18, 2012 - 10:18 pm | Permalink

    This sets a good example for using external functions. Great job researching and sharing.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>