+ Reply to Thread
Results 1 to 8 of 8

trying to code is a test to see if a program/application is already running

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    trying to code is a test to see if a program/application is already running

    I was wondering if someone could help me figure this out, I have the code to launch it working fine, however I forgot to take into account people may already have the program running which would cause an issue launching a second version.

    Im trying to code in a check before launching into the program launch however, it isn't working for me. Any ideas as always would be appreciated greatly. If the app check comes back true then I need to jump down to the check for login, which I think...

    Sub Darkside_Launch()
    
        Dim x As Variant
        Dim Path As String
        Dim s As New AutSess
        Dim autEclps As Object
        
            Set autEclps = CreateObject("Pcomm.auteclps")
            Set autECLOIA = CreateObject("Pcomm.autecloia")
            
            sApp = "3270 Terminal"
            If IsAppRunning(sApp) = True Then
            MsgBox ("Darkside is already Running")
            Else
        ' Set the Path variable equal to the path of your program's installation
             Path = "generic path"
    
             x = Shell("generic path", 0)
             
            End If
            
             Application.Wait (Now + TimeValue("0:00:10"))
            
                s.SetConnectionByName ("A")
                s.autEclps.StartCommunication
             If s.autEclps.SearchText("Userid . . . .") Then
                Login.Show vbModeless
                
             End If
        
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,243

    Re: trying to code is a test to see if a program/application is already running

    See if this helps,

    http://vbadud.blogspot.com/2007/04/g...-check-if.html
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: trying to code is a test to see if a program/application is already running

    for example
    [CODEIf Tasks.Exists(Name:="Calc") = False Then
    Shell "Calc.exe", vbNormalFocus 'run calc
    Tasks.Item("Calc").Close 'exit calc
    End If][/CODE]
    Last edited by tim201110; 01-17-2017 at 04:47 PM. Reason: kirilitsa

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,102

    Re: trying to code is a test to see if a program/application is already running

    Not something I've tried, but this might give you food for thought.

    http://stackoverflow.com/questions/2...ing-with-excel
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: trying to code is a test to see if a program/application is already running

    Declare a public variable as Boolean

    At the start of your progran check if the flag is true, if it is then quit

    If Not then Set the Variable to true

    When the program ends set your variable to False

    This is an extract from a userform application:


    Public ChangeFlagAs Boolean
    
    Private Sub TelNo()
    If ChangeFlag = True Then Exit Sub
    ChangeFlag = True
    temp = TextBox5.Text
    NO = Replace(Me.Controls("Textbox" & T).Text, " ", "")
    
    If NO = "" Or Not IsNumeric(NO) Then GoTo 200
    
    Count = 1: Length = Len(NO)
    
    10 temp = Mid(NO, Count, 1)
    
    If Asc(temp) > 47 And Asc(temp) < 58 Then GoTo 20
    
    NO = Left(NO, Count - 1): If Count < Length Then NO = NO & Right(Text, Length - Count)
    
    Length = Length - 1: Count = Count - 1
    
    20 Count = Count + 1: If Count <= Length Then GoTo 10
    
    If Len(NO) > 4 Then NO = Left(NO, 4) & " " & Right(NO, Len(NO) - 4)
    If Len(NO) > 8 Then NO = Left(NO, 8) & " " & Right(NO, Len(NO) - 8)
    If Len(NO) > 13 Then NO = Left(NO, 13)
    Me.Controls("Textbox" & T).Text = NO
    
    200 ' exit
    ChangeFlag = False
    
    End Sub
    Last edited by mehmetcik; 01-17-2017 at 05:17 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  6. #6
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: trying to code is a test to see if a program/application is already running

    Thanks for the ideas, I have been to both the provided links prior to posting, and I am using the function provided by the second. I am however still not getting the desired result, It just blows through to launching a second version of the program even if the program is already open.

    based off what I have for code thus far, what would be the best course of action? also, thank you all again for the help thus far.

  7. #7
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: trying to code is a test to see if a program/application is already running

    THe best course of action is to use the facilities provided by your application; PCOMMS in this case.

    PCOMMS provides a method to return the number of active terminal windows natively. For example:
    Sub GetTermCount()
    
       Dim autECLConnList as Object
    
       On Error Goto Catch
       Set autECLConnList = CreateObject("PCOMM.autECLConnList")
       autECLConnList.Refresh
       MsgBox "There are " & cStr(autECLConnList.Count) & " terminal sessions running...", vbinformation
    
    Finally:
    
       Set autECLConnList = Nothing
       Exit sub
    
    Catch:
    
       MsgBox "ERROR: " & Err.Description & vbCrLf & "Unable to get count of terminal sessions", vbExclamation, "Error"
       Resume Finally
    
    End Sub
    Written freehand and untested - PCOMMS not available on an Android tablet

  8. #8
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Re: trying to code is a test to see if a program/application is already running

    Cytop thank you for pointing out the PCOMM portion I was missing, Used that with what I had and a few changes and boom we have a working line that tests, and logically moves through as required. Thank you to all you for the collaboration


    Sub Darkside_Launch()
    
        Dim x As Variant
        Dim Path As String
        Dim s As New AutSess
        Dim autEclps As Object, autECLConnList As Object
        
            Set autEclps = CreateObject("Pcomm.auteclps")
            Set autECLOIA = CreateObject("Pcomm.autecloia")
            Set autECLConnList = CreateObject("PCOMM.autECLConnList")
            
        autECLConnList.Refresh
        If CStr(autECLConnList.Count) < 1 Then
        GoTo darksiderun
        Else
        If CStr(autECLConnList.Count) = 1 Then MsgBox ("Darkside is already running")
        GoTo VerifyLogin
        End If
    
    
    darksiderun:
            
        ' Set the Path variable equal to the path of your program's installation
             Path = "Generic.bat"
    
             x = Shell("Generic", 0)
            
             Application.Wait (Now + TimeValue("0:00:10"))
            
                s.SetConnectionByName ("A")
                s.autEclps.StartCommunication
             If s.autEclps.SearchText("Userid . . . .") Then
                Login.Show vbModeless
                
             End If
            Exit Sub
            
             
    VerifyLogin:
    
        Application.Wait (Now + TimeValue("0:00:05"))
            
                s.SetConnectionByName ("A")
                s.autEclps.StartCommunication
             If s.autEclps.SearchText("Userid . . . .") Then
                Login.Show vbModeless
            Else
                Exit Sub
                
             End If
        
        
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] First Check An Application is running or not using vba then run the code
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-30-2016, 07:16 AM
  2. A problem when running program code residing in another workbook
    By eMKaa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-17-2016, 06:41 AM
  3. Code to find if Application is running or available
    By annux08 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-06-2015, 12:49 AM
  4. [SOLVED] VBA Code to test if running on Mac or PC
    By jaslake in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2015, 02:16 PM
  5. [SOLVED] program working in the code application, but not the excel sheet
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2013, 09:20 AM
  6. If statement to test value in cell before running code
    By Motox in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2012, 04:49 AM
  7. VBA Delete Code not running in full program
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2010, 12:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1