Forum Discussion

nbenitus's avatar
nbenitus
Contributor
15 years ago

How to run an application with changing name

Hi,



I am trying to run an application which name keeps changing each day.



I can't add it to the list of TestedApps for this reason.



I know the name and path of the application, but I can't seem to be able to execute it using the script.



Is there a command that would look like Application.Open(<path_to_my_application>)?



Thanks in advance !



Benoit



(On a side note, how do I check if an application is currently running or not?)

3 Replies


  • Hi Benoit,





    Here is the script demonstrating how to launch an application whose executable resides in the given folder:





        Dim path

        path = "C:\SomeFolder\"

        Set foundFiles = aqFileSystem.FindFiles(path, "*.exe")

        If Not foundFiles Is Nothing Then  

            Set WshShell = CreateObject("WScript.Shell")

            ' Launches the first .exe file found

            WshShell.Exec(path + foundFiles.Item(0).Name)

        Else

            Log.Message "No exe files found"  

        End If







    See the 'aqFileSystem.FindFiles' help topic for more information.







    how do I check if an application is currently running or not?



    Check whether its process exists by using the 'WaitProcess' method:





        Set p = Sys.WaitProcess("notepad")

        If p.Exists Then

            Log.Message "Process exists"

        Else

            Log.Message("Process does not exist")

        End If

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Benoit,



    You can add the current version of the application to the TestedApps list (under e.g. 'myApp' name) and then execute the following (untested DelphiScript):

    app := TestedApps.myApp;

    app.FullFileName := '<fully-qualified file name of the next version of the tested application>';

    app.WorkFolder := '<new path to the tested application>';

    app.Run;



    See the 'TestedApp Object' help topic for more details.



    To figure-out if the application is running you may use something like:

    if (Sys.WaitProcess(app.FileName, 500).Exists) then

      // application is running

      ...

    else

      ...



    Note: you should check with Windows Task Manager or TC Object Browser if the name of the tested application process contains '.exe' or not. In the former case the code from above should work. In the latter case the 'app.FileName' should be replaced with 'Utilities.ChangeFileExt(app.FileName, '')'.



    Hope this will help...
  • I tried your suggestions and, again, everything works.



    Thanks guys !!!