Detecting if a Certain program is running or Installed on system. 
Author Message
 Detecting if a Certain program is running or Installed on system.

Hi,

I am working on a project in Visual Basic and wanted to know if there is a
way
to find out, say by searching in Registry or by checking
the id of all programs running on system if
say Zone Alarm is installed on the system or say if
Internet explorer is currently running.

Let me give you some more details to help describe the situation.

I can run an api to check for the current active window and find out if its
internet explorer.  But programs like zone alarm or Norton Anit Virus runs
in systray and cant be
grabbed by that api call.  Is there a way to find out all running programs
and by their ids find out what they are, or if not, or say if its not
currently runnig but is installed.  Is there a way i can
search registry for keys from those programs to find out if its installed or
running.

TIA



Sat, 14 Aug 2004 01:27:22 GMT  
 Detecting if a Certain program is running or Installed on system.
The following code should get you started...

In a new VB app...

On Form1...

1) Add a text box
2) Add a command button
3) Add a label
4) Add the following code...

Option Explicit

Private Declare Function EnumWindows Lib "User32" ( _
            ByVal lpEnumFunc As Long, _
            ByVal lParam As Long) _
        As Long

Private Sub Command1_Click()

    g_WindowHwnd = 0
    g_WindowText = Text1.Text

    Call EnumWindows(AddressOf mFindWindow.EnumWindowsCallback, 0)

    If (g_WindowHwnd <> 0) Then
            Label1.Caption = "Window found, hWnd: " & CStr(g_WindowHwnd)
    Else:   Label1.Caption = "Window not found"
    End If

End Sub

On a new Code Module (*.bas)...

1) Rename the code module to: MFindWindow
2) Add the following code...

Option Explicit

Public g_WindowText As String
Public g_WindowHwnd As Long

Private Declare Function GetWindowText Lib "User32" _
        Alias "GetWindowTextA" ( _
            ByVal hWnd As Long, _
            ByVal lpString As String, _
            ByVal cch As Long) _
        As Long

Private Declare Function GetClassName Lib "User32" _
        Alias "GetClassNameA" ( _
            ByVal hWnd As Long, _
            ByVal lpString As String, _
            ByVal cch As Long) _
        As Long

Private Const MAX_STRING_LEN As Long = 256
'

Public Function EnumWindowsCallback(ByVal hWnd As Long, ByVal lpData As Long) As Long

    Dim iLen As Long
    Dim sText As String

    sText = String$(MAX_STRING_LEN, 0)
    iLen = GetWindowText(hWnd, sText, MAX_STRING_LEN - 1)

    ' This just checks for an exact match for the Window Caption

    ' This IS CASE SENSITIVE so the test string must match case
    ' as well as letters/spaces/punctuation/etc.

    ' You can do the same thing for the Class Name or you can
    ' check for a partial match for either and you can make this
    ' case insensitive using InStr() with the vbTextCompare flag.

    If (Left$(sText, iLen) = g_WindowText) Then
            g_WindowHwnd = hWnd
    Else:   EnumWindowsCallback = 1
    End If

End Function

Now run the app in the VB IDE...

Type the following string into the text box and click the command button, if ZoneAlarm is running
the code should find it and return an hWnd...

ZoneAlarm Pro

--
Mark E Alsop



Sat, 14 Aug 2004 09:56:25 GMT  
 Detecting if a Certain program is running or Installed on system.
Hi,

Someone can also use WMI (Microsoft WMI Scripting V1.2 Library) :

To Start NOTEPAD on AGANNAZAR:
----------------------------------------------------

Public Sub RemoteEx()
Dim process As WbemScripting.SWbemObject
Dim processID As Long
Dim Result As Long

    ' The following is just one line
    Set process =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\Agannazar\root\cimv2:
Win32_Process")

    Result = process.Create("notepad", Null, Null, processID)

End Sub
-------------------------------------------------------

To see all the running app on AGANNAZAR:
---------------------------------------------------------
Public Sub GetAllProcesses()
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject

    ' The following is just one line
    Set objs = GetObject("winmgmts:\\Agannazar").ExecQuery("SELECT * FROM
Win32_Process")

    For Each obj In objs
        Debug.Print obj.Name & ", " & obj.ExecutablePath
    Next obj

End Sub
------------------------------------------------------------

To stop NOTEPAD on AGANNAZAR:
----------------------------------------------------------
Public Sub StopNotePad()
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject

    ' The following is just one line
    Set objs = GetObject("winmgmts:\\Agannazar").ExecQuery("SELECT * FROM
Win32_Process  WHERE Name='Notepad.exe'")

    For Each obj In objs
        Debug.Print obj.Terminate
    Next obj

End Sub
----------------------------------------------------------

WMI is installed by default on W2000 and XP.

Hoping it may help,
Vanderghast, Access MVP



Quote:
> The following code should get you started...

> In a new VB app...

> On Form1...

> 1) Add a text box
> 2) Add a command button
> 3) Add a label
> 4) Add the following code...

> Option Explicit

> Private Declare Function EnumWindows Lib "User32" ( _
>             ByVal lpEnumFunc As Long, _
>             ByVal lParam As Long) _
>         As Long

> Private Sub Command1_Click()

>     g_WindowHwnd = 0
>     g_WindowText = Text1.Text

>     Call EnumWindows(AddressOf mFindWindow.EnumWindowsCallback, 0)

>     If (g_WindowHwnd <> 0) Then
>             Label1.Caption = "Window found, hWnd: " & CStr(g_WindowHwnd)
>     Else:   Label1.Caption = "Window not found"
>     End If

> End Sub

> On a new Code Module (*.bas)...

> 1) Rename the code module to: MFindWindow
> 2) Add the following code...

> Option Explicit

> Public g_WindowText As String
> Public g_WindowHwnd As Long

> Private Declare Function GetWindowText Lib "User32" _
>         Alias "GetWindowTextA" ( _
>             ByVal hWnd As Long, _
>             ByVal lpString As String, _
>             ByVal cch As Long) _
>         As Long

> Private Declare Function GetClassName Lib "User32" _
>         Alias "GetClassNameA" ( _
>             ByVal hWnd As Long, _
>             ByVal lpString As String, _
>             ByVal cch As Long) _
>         As Long

> Private Const MAX_STRING_LEN As Long = 256
> '

> Public Function EnumWindowsCallback(ByVal hWnd As Long, ByVal lpData As
Long) As Long

>     Dim iLen As Long
>     Dim sText As String

>     sText = String$(MAX_STRING_LEN, 0)
>     iLen = GetWindowText(hWnd, sText, MAX_STRING_LEN - 1)

>     ' This just checks for an exact match for the Window Caption

>     ' This IS CASE SENSITIVE so the test string must match case
>     ' as well as letters/spaces/punctuation/etc.

>     ' You can do the same thing for the Class Name or you can
>     ' check for a partial match for either and you can make this
>     ' case insensitive using InStr() with the vbTextCompare flag.

>     If (Left$(sText, iLen) = g_WindowText) Then
>             g_WindowHwnd = hWnd
>     Else:   EnumWindowsCallback = 1
>     End If

> End Function

> Now run the app in the VB IDE...

> Type the following string into the text box and click the command button,

if ZoneAlarm is running

- Show quoted text -

Quote:
> the code should find it and return an hWnd...

> ZoneAlarm Pro

> --
> Mark E Alsop




Sat, 14 Aug 2004 20:39:56 GMT  
 Detecting if a Certain program is running or Installed on system.
The easy way:

On Error Resume Next
AppActivate ("ZoneAlarm") 'or whatever the title may be
If Err Then MsgBox "that wasn't running"
On Error Goto 0 'or your original error handler

Fortune&Glory,
Robert


Quote:
> Hi,

> I am working on a project in Visual Basic and wanted to know if there is a
> way
> to find out, say by searching in Registry or by checking
> the id of all programs running on system if
> say Zone Alarm is installed on the system or say if
> Internet explorer is currently running.

> Let me give you some more details to help describe the situation.

> I can run an api to check for the current active window and find out if
its
> internet explorer.  But programs like zone alarm or Norton Anit Virus runs
> in systray and cant be
> grabbed by that api call.  Is there a way to find out all running programs
> and by their ids find out what they are, or if not, or say if its not
> currently runnig but is installed.  Is there a way i can
> search registry for keys from those programs to find out if its installed
or
> running.

> TIA



Sun, 15 Aug 2004 00:48:08 GMT  
 Detecting if a Certain program is running or Installed on system.
Thanks guys....gona test them out

GREAT  help

8)



Quote:
> The following code should get you started...

> In a new VB app...

> On Form1...

> 1) Add a text box
> 2) Add a command button
> 3) Add a label
> 4) Add the following code...

> Option Explicit

> Private Declare Function EnumWindows Lib "User32" ( _
>             ByVal lpEnumFunc As Long, _
>             ByVal lParam As Long) _
>         As Long

> Private Sub Command1_Click()

>     g_WindowHwnd = 0
>     g_WindowText = Text1.Text

>     Call EnumWindows(AddressOf mFindWindow.EnumWindowsCallback, 0)

>     If (g_WindowHwnd <> 0) Then
>             Label1.Caption = "Window found, hWnd: " & CStr(g_WindowHwnd)
>     Else:   Label1.Caption = "Window not found"
>     End If

> End Sub

> On a new Code Module (*.bas)...

> 1) Rename the code module to: MFindWindow
> 2) Add the following code...

> Option Explicit

> Public g_WindowText As String
> Public g_WindowHwnd As Long

> Private Declare Function GetWindowText Lib "User32" _
>         Alias "GetWindowTextA" ( _
>             ByVal hWnd As Long, _
>             ByVal lpString As String, _
>             ByVal cch As Long) _
>         As Long

> Private Declare Function GetClassName Lib "User32" _
>         Alias "GetClassNameA" ( _
>             ByVal hWnd As Long, _
>             ByVal lpString As String, _
>             ByVal cch As Long) _
>         As Long

> Private Const MAX_STRING_LEN As Long = 256
> '

> Public Function EnumWindowsCallback(ByVal hWnd As Long, ByVal lpData As
Long) As Long

>     Dim iLen As Long
>     Dim sText As String

>     sText = String$(MAX_STRING_LEN, 0)
>     iLen = GetWindowText(hWnd, sText, MAX_STRING_LEN - 1)

>     ' This just checks for an exact match for the Window Caption

>     ' This IS CASE SENSITIVE so the test string must match case
>     ' as well as letters/spaces/punctuation/etc.

>     ' You can do the same thing for the Class Name or you can
>     ' check for a partial match for either and you can make this
>     ' case insensitive using InStr() with the vbTextCompare flag.

>     If (Left$(sText, iLen) = g_WindowText) Then
>             g_WindowHwnd = hWnd
>     Else:   EnumWindowsCallback = 1
>     End If

> End Function

> Now run the app in the VB IDE...

> Type the following string into the text box and click the command button,

if ZoneAlarm is running

- Show quoted text -

Quote:
> the code should find it and return an hWnd...

> ZoneAlarm Pro

> --
> Mark E Alsop




Sun, 15 Aug 2004 13:02:15 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Detecting if a Certain program is running or Installed on system.

2. How to detect if certain app is running

3. API to check if a certain program is running

4. Detecting is a program is installed on the user's machine

5. Detecting If a program is installed

6. Detecting If a program is installed

7. Detecting If a program is installed

8. Detecting If a program is installed

9. VB4 16bit App runs from CD without installing components into windows\system

10. I am Looking for certain ico. type images

11. Help needed detecting if a program is running

12. Two parter: Detect app already running, then pass command args to original program

 

 
Powered by phpBB® Forum Software