Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
8 years ago
Solved

Launching the Desktop Application

Hi All

 

Am Trying to launch the application by using the below code :

 

def test():
 WinFolder = Sys.OSInfo.WindowsDirectory
 DbgServices.LaunchTestedApplication(WinFolder +"C:\Users\User1\Desktop\Teachers.lnk")
 app = Sys.Process("Teachers").Exists
  # Checks whether Notepad has started successfully
 if app:
    Log.Message("Teachers app has been started successfully.")
 else:
    Log.Message("Teachersapp hasn't been started.")
   

But it is unable to launch the Application and am facing the error Message :

 

Erro.png

 

Did I went wrong some where in the code  , Even if I changed the code a little like this

 

def test():
DbgServices.LaunchTestedApplication("C:\Users\User1\Desktop\Teachers.lnk")
 app = Sys.Process("Teachers").Exists
  # Checks whether Notepad has started successfully
 if app:
    Log.Message("Teachers app has been started successfully.")
 else:
    Log.Message("Teachersapp hasn't been started.")

Still the Same error as showed in the image above

 

Please guide me

  • JackSparrow's avatar
    JackSparrow
    8 years ago

    tristaanogre ya I tried that code which you referred it was not working and  that link is the shortcut link which am trying to access , since the application is in some other virtual network .

     

    HKosova am about to post that I found the way of launching as you mentioned " testedapp " , which I have created & given the total virtual network path in it and I used .Run which launched the application :D

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Couple of things to check.

    First of all, I'm not 100% familiar with Python but I know that in many languages, the backslash (\) character in a string is a reserved character and needs to be doubled in order for it to be properly parsed.  So, you're one line where you have

     

     DbgServices.LaunchTestedApplication(WinFolder +"C:\Users\User1\Desktop\Teachers.lnk")

    Change to

     

     DbgServices.LaunchTestedApplication(WinFolder +"C:\\Users\\User1\\Desktop\\Teachers.lnk")

    And see if that helps out.

    Secondly, this line

     

    app = Sys.Process("Teachers").Exists

    Will actually return an error if the application isn't running.  The reason being is that you cannot check the "Exists" property if the object itself doesn't exist.  Common error. :)

    So... change that line of code to

     

    app = Sys.WaitProcess("Teachers").Exists

     

    So... those are the two obvious problems I see in your code.  

     

    One final item that is more of a "style" thing is that you don't really need to have the extra line for checking the Exists property.  The DbgServices call you are making returns the process object if it exists and returns an empty stub if it does not.  So...  You can change your code to simply be.

     

    def test():
     WinFolder = Sys.OSInfo.WindowsDirectory
     app = DbgServices.LaunchTestedApplication(WinFolder +"C:\\Users\\User1\\Desktop\\Teachers.lnk")
      # Checks whether Notepad has started successfully
     if app:
        Log.Message("Teachers app has been started successfully.")
     else:
        Log.Message("Teachersapp hasn't been started.")
       

     

    Make those corrections and see if that helps.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      tristaanogre thanks for the detailed info,  as suggested I have changed but facing the python runtime error at this point

       DbgServices.LaunchTestedApplication(WinFolder+"C:\\Users\\saikris\\Desktop\\Teachers_debug.lnk")
      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        JackSparrow wrote:

        tristaanogre thanks for the detailed info,  as suggested I have changed but facing the python runtime error at this point

         DbgServices.LaunchTestedApplication(WinFolder+"C:\\Users\\saikris\\Desktop\\Teachers_debug.lnk")

        Something I just realized... you are using the "WinFolder" variable AND then pointing to the C:\Users directory... so, in other words, the path you're sending to the launch is C:\Windows\C:\Users|...

        Remove the "WinFolder+" from your string so you have.

         

        DbgServices.LaunchTestedApplication("C:\\Users\\saikris\\Desktop\\Teachers_debug.lnk")

        Also, as asked, is there a particular reason why you are using DbgServices instead of TestedApps and why are you launching the .lnk instead of the .exe?

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi JackSparrow,

     

    Could you please elaborate on what exactly you are trying to accomplish? Is there a specific reason you use DbgServices.LaunchTestedApplication instead of adding the app to TestedApps and using TestedApps.appname.Run()? Why are you specifying a shortcut (.lnk) instead of the actual path to the .exe file? More details will help us get to the solution for you.