get programs name in VBA

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi,

I want to get all of the programs name in VBA.
I can find a program name by FindWindow Function:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

But I can't get all of the programs name!!!
any help?

best wishes
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you mean all programs that are open, or all programs that are installed on your machine?
 
Upvote 0
Hi,

This lists ALL programs that are open (including ones you can't visibly see). It will only work in Excel 2000 because Excel 97 doesn't support the AddressOf operator.

Run the procedure ListApps to get a list of all programs running.

Code:
'This code modified from code found at this address:-
'http://216.26.168.92/vbapi/articles/intro/part05.html

Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) 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 EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private CellNumber As Long

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim slength As Long, buffer As String  ' title bar text length and buffer
    Dim retval As Long
    Static winnum As Integer

    winnum = winnum + 1  ' one more window enumerated....
    slength = GetWindowTextLength(hwnd) + 1  ' get length of title bar text
    If slength > 1 Then    ' if return value refers to non-empty string
        buffer = Space(slength)  ' make room in the buffer
        retval = GetWindowText(hwnd, buffer, slength)  ' get title bar text
        Cells(CellNumber, 1) = winnum
        Cells(CellNumber, 2) = Left(buffer, slength - 1)

        Debug.Print "Window #"; winnum; " : ";  ' display number of enumerated window
        Debug.Print Left(buffer, slength - 1)  ' display title bar text of enumerated window
        CellNumber = CellNumber + 1
    End If

    EnumWindowsProc = 1  ' return value of 1 means continue enumeration
End Function


Sub GetThem()
' *** Place this code wherever you want to enumerate the windows. ***
    Dim retval As Long  ' return value

    CellNumber = 2
    Cells(1, 1) = "Window Number"
    Cells(1, 2) = "Application Name"
    ' Use the above callback function to list all of the enumerated windows.  Note that lParam is
    ' set to 0 because we don't need to pass any additional information to the function.
    retval = EnumWindows(AddressOf EnumWindowsProc, 0)

End Sub
 
Upvote 0
Hi again,

OK , program works....
but I can't distinguish between folder name and program name!!!!!
how can I do it?
any help?

best wishes
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top