Forum Discussion

subbu_valliappa's avatar
subbu_valliappa
Contributor
11 years ago

"Access is denied" issue in scripting

We have this script to terminate a process if it still exists:



//terminate process if it still exists

p := Sys.WaitProcess('propx32');

if p.Exists then

  begin

    p.Terminate();

    Log.Warning('A running process has been terminated');

  end;



It occasionally fails on the test machine when our scripts run overnight with "Access is denied" issue logged in the test logs. The user account that is used for this script run has admin access on the test machine so I'm not sure what is going on here.



Any help or suggestions would be greatly appreciated.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Is this inside a loop? It's possible that it's returning to the p.Terminate() method before the first completed. If so try this:



    //terminate process if it still exists

    p := Sys.WaitProcess('propx32');

    if p.Exists then

      begin

        p.Terminate();

         BuiltIn.Delay(1500);

        Log.Warning('A running process has been terminated');

      end;
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Some other things to check:

    Is the function getting called repeatedly?

    Is the application you are trying to terminate running as Administrator?

    Are you using an OS that requires elevated permissions to terminate a process?

    Are you running Test Complete as Administrator?

    Does adding the delay from my previous post make any difference?
  • chicks's avatar
    chicks
    Regular Contributor
    I have started to see this issue as well using IE9.   See function CloseIE below.

    I ichanged the code from Sys.Process... Close() to Sys.Process...Terminate() to avoid having to deal with the are you sure you want to leave popup.



    However, I now get access denied referencing the .Terminate()  line.



    NOTE:   When I tried to use this routine



    function trial43014a() {

        Sys.Process(browserToUse).Terminate();

        Sys.Process(browserToUse).Terminate();



    }




    I never got "access is denied" .  I just got  the process was not found.



    function CloseIE()

    {

        //Try timeOutWait times to close IE

        var count = 0;

      while(Sys.WaitProcess(browserToUse, 0).Exists)

    //  while (Sys.WaitProcess(browserToUse, 1500, 1).Exists)

      {

    //Sys.Refresh();// Sys.Process("iexplore').Close() 7.13.2012

        

    // 4/29/14  previously was .Close() stopping due to "are you sure you want to leave" popup  use .Terminate()

        Sys.Process(browserToUse).Terminate();

        Sys.Refresh();

        //while(Sys.WaitProcess(browserToUse, 1000).Exists){}

        

        // I've seen an infinite loop when this is called and a modal popup "are you sure you want to leave"

        // when in GMAIL occurs...  Curt H. 6.22.2012

          if (count > 9) {

            Log.Error("Attempted to close browser more than 9 times ");

            Sys.Process(browserToUse).Terminate();

            throw new Error("excessive Browser closures" );

         }

         count++;



      }

    }


  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    This is unrelated, but thought it may help you Curt:






    function closeBrowser(browsername){


    var myBrowsers = (new VBArray(Sys.FindAll('Name','*' + browsername + '*',1,true))).toArray();


    for (var c = 0;c < myBrowsers.length;c++){


     if (myBrowsers.Exists){


      myBrowsers.close();


      //click popup if it exists here


      }


     }


    }


  • Great, back to my question then.



    I have added the delay and so far the scripts are working alright. It only fails occassionally so I'll keep an eye on that.



    And yes, I'm running both TestComplete and the other program as Administrator. The function gets called at the end of every script - we have 30+ scripts running overnight.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    So if adding the delay helped at all then more than likely you are trying to terminate a process that is already being terminated/closed. Use a similar approach to my previous example for closing browsers or increase the delay to allow more time for memory to clear before attempting to terminate the process again.
  • Adding the delay didn't help actually. We keep on getting "Access is denied" issue intermittently when closing the application.



    Just to recap, we are running both TestComplete and the application as administrator. The test machine is Windows 7.



    Could there be anything else that causes this?
  • chrisb's avatar
    chrisb
    Regular Contributor
    I had the same problem. I believe the issue was caused by trying to close a process that was no longer running. Resolved this problem for good by increasing the delay before checking to see if the process still running and also adding some code to break out of the loop  if IE was determined to no longer be running:




    function TerminateIEProcesses() {


        var process, i;


     


        for (i = 0; i < 20; i++) {


     


            process = Sys.WaitProcess("iexplore", 2000);


            


            if (!process.Exists) {


                break;


            }


            process.Terminate();


            aqUtils.Delay(1500);


        }


     


     


    }