[VB.NET] Detect if program is run

Discussion in 'Mixed Languages' started by jcgo16, Feb 8, 2012.

  1. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    how to detect if a program is run

    for example

    firefox.exe, if firefox is run, a message box will appear

    but if i rename firefox.exe into aw.exe, how could i know if it is firefox?
     
  2. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    631
    60
    #2 NICK@NUMBER11, Feb 8, 2012
    Last edited by a moderator: Apr 20, 2017
    here is a simple script that will check if firefox.exe is running, if so it will stop ...
    Code:
    Set WshShell = WScript.CreateObject ("WScript.Shell")
    Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")
    '==============================================================================================
    For Each objProcess in colProcessList
    If objProcess.name = "firefox.exe" then
    vFound = True
    End if
    Next
    If vFound = True then
    WshShell.Run ("C:\Windows\system32\cmd.exe")
    WshShell.sendkeys "taskkill /IM firefox.exe"
    WshShell.SendKeys "{ENTER}"
    Else
    Msgbox("Not Installed")
    End If 
     
  3. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    ok lets say i run firefox but in different name, like aw.exe

    i really want to close firefox
     
  4. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    631
    60
    taskkill /IM firefox.exe this closes the program, change to any .exe name such as aw.exe
     
  5. NICK@NUMBER11

    NICK@NUMBER11 MDL Expert

    Mar 23, 2010
    1,354
    631
    60
    #5 NICK@NUMBER11, Feb 8, 2012
    Last edited by a moderator: Apr 20, 2017
    or another way call from a bat file is;

    Code:
    @echo off
    set tempfile=bdw.txt
    
    del %tempfile%
    tasklist > %tempfile%
    type %tempfile% | find /i "firefox.exe"
    if errorlevel 0 if not errorlevel 1 goto IsRunning
    start firefox
    
    :exit
    del %tempfile%
    pause
    exit
    
    :IsRunning
    echo IsRunning
    goto exit
     
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,097
    120
    #6 Josh Cell, Feb 8, 2012
    Last edited by a moderator: Apr 20, 2017
    Here's the code:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            If (Process.GetProcessesByName("YourProccessNameWithout.EXE").Length >= 1) Then
                MessageBox.Show("Application already running in the system!", "MyApplication", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Environment.Exit(0)
            End If
        End Sub
    End Class
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. jcgo16

    jcgo16 MDL Junior Member

    Sep 16, 2010
    74
    2
    0
    what about if a dll is running?