Changing LoadRunner Agent to run as a process or service

During the installation of LoadRunner if you select “Allow virtual users to run on this machine without user login”, the LoadRunner agent will run as a Windows system service called “LoadRunner Agent Service”.

If you choose “Manually log in to the Load Generator “, the LoadRunner agent will be run as a process named magentproc.exe.  This means you need to start the LoadRunner agent manually each time you reboot the PC/server or you need to put the LoadRunner agent process into a windows startup group.

Some vUser types will only run if the agent is running as a service (GUI, SAP, Citrix etc.). This is because they need to run in a user context.

After installation, to switch from running the LoadRunner agent as a service to running as a process:
magentservice.exe -remove
Add this shortcut to the startup folder – “C:\Program Files (x86)\HP\LoadRunner\LAUNCH_SERVICE\bin\magentproc.exe”

After installation, to switch from running the LoadRunner agent as a process to running as a service:
Remove the LoadRunner Agent Process from the Startup folder
magentservice.exe -install

N.B. You need admin rights to do this. The magentservice.exe file is in the C:\Program Files (x86)\HP\LoadRunner\bin or C:\Program Files\HP\LoadRunner\bin folder.

Calculate epoch time for last midnight

I had a requirement to calculate the epoch time in milliseconds for midnight at the start of today.

This function calculates this value.

 


Action() {
// Epoch time on 1/1/2010 00:00:00 was 1262304000
// N.B, If running this in subsequent years, change the hard coded value on the next line. // Value obtained from http://www.epochconverter.com/
//Declare integer iEpochStartYear – use it to hold the Epoch time (in secs) on 1st January this year.
int iEpochStartYear = 1262304000;      
//Declare integer to hold calculated value of Epoch time last midnight.
int iEpochSecsLastMidnight;            
//Declare integer to hold the current day (i.e. num of days since 1st Jan 2010)
int iCurrentDay;                  
//Declare char to contain final output value (N.B in milliseconds, not seconds)
char sEpochMilliSecsLastMidnight[13];   
// Current day is number of days since start of 1st Jan 2010.
// Need to subtract one day since midnight is nominally the end of yesterday (rather than the start of today).
lr_save_datetime(“%j “, DATE_NOW – ONE_DAY, “sCurrentDay”);
//Convert the SCurrentDay string to an integer
iCurrentDay = atoi(lr_eval_string(“{sCurrentDay}”));               
//Calculate Epoch time (in seconds) for last midnight
iEpochSecsLastMidnight = iEpochStartYear + (iCurrentDay * 86400);     
//Write Epoch time (in milliseconds) for last midnight to a string
sprintf(sEpochMilliSecsLastMidnight, “%d000”, iEpochSecsLastMidnight);    
lr_output_message(sEpochMilliSecsLastMidnight);
return 0; }

LoadRunner function write to and read data from external file

On a client site recently, I had a requirement to encrypt a small amount of data which needed to be re-used later in a LoadRunner script. The encryption was done by OpenSSL; whilst it was easy to use OpenSSL to encrypt the data in question, it proved extremely difficult to incorporate the OpenSSL functions into LoadRunner.

As a work-around, I wrote a function which writes output to an external file with a unique filename. LoadRunner can then use the external OpenSSL executable by using the system function to call an external DOS command, if the output from this command is written to an output file, the script can then read the data back in from the output file and use it later in the script.

This seems quite convoluted but it works!!

The function can be downloaded in a working sample script.