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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Do you mean all programs that are open, or all programs that are installed on your machine?
 

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
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
 

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
Hi Dan,

thanks for your reply and for your EXCELLENT ANSWER...

best wishes

Hamid
 

aryan_hr

Board Regular
Joined
Feb 19, 2002
Messages
222
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
 

Forum statistics

Threads
1,144,148
Messages
5,722,787
Members
422,458
Latest member
Muirzy

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
Top