cancel
Showing results for 
Search instead for 
Did you mean: 

How to run an application with changing name

nbenitus
Contributor

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 3

RE: How to run an application with changing name


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

--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
AlexKaras
Community Hero

RE: How to run an application with changing name

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...
Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
nbenitus
Contributor

RE: How to run an application with changing name

I tried your suggestions and, again, everything works.



Thanks guys !!!
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors