Get the path of the installed WhatsApp software

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Get the path of the installed WhatsApp software

Post by YasserKhalil »

Hello everyone
I am trying to find the path of the WhatsApp software and I have found the following code but doesn't work for WhatsApp

Code: Select all

#If Win64 Then
    Declare PtrSafe Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
        (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
#Else
    Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
        (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
#End If

Const SYS_OUT_OF_MEM        As Long = &H0
Const ERROR_FILE_NOT_FOUND  As Long = &H2
Const ERROR_PATH_NOT_FOUND  As Long = &H3
Const ERROR_BAD_FORMAT      As Long = &HB
Const NO_ASSOC_FILE         As Long = &H1F
Const MIN_SUCCESS_LNG       As Long = &H20
Const MAX_PATH              As Long = &H104

Const USR_NULL              As String = "NULL"
Const S_DIR                 As String = "C:\"


Function GetInstallDirectory(ByVal usProgName As String) As String

    Dim fRetPath As String * MAX_PATH
    Dim fRetLng As Long

    fRetLng = FindExecutable(usProgName, S_DIR, fRetPath)

    If fRetLng >= MIN_SUCCESS_LNG Then
        GetInstallDirectory = Left$(Trim$(fRetPath), InStrRev(Trim$(fRetPath), "\"))
    End If

End Function

Sub ExampleUse()

Dim x As String

x = "excel.exe"

Debug.Print GetInstallDirectory(x)

End Sub
I posted here too
https://www.mrexcel.com/board/threads/g ... e.1137003/

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get the path of the installed WhatsApp software

Post by HansV »

For me, FindExecutable works only for the Office applications. It fails for all other applications that I tried.

According to FindExecutableA function:
Retrieves the name of and handle to the executable (.exe) file associated with a specific document file.
(...)
Use FindExecutable for documents. If you want to retrieve the path of an executable file, use the following:
(...)
You may need AssocQueryStringA, but there are lots of posts on other forums complaining that it doesn't work.

Why do you need to find the path to WhatsApp?
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: Get the path of the installed WhatsApp software

Post by YasserKhalil »

Thanks a lot my tutor.
I am trying to find the WhatsApp path as I am working on scraping code that I need to check the path by the code itself.
Can you post code for AssocQueryStringA as I have no idea about it so as to try on my side?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get the path of the installed WhatsApp software

Post by HansV »

Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: Get the path of the installed WhatsApp software

Post by YasserKhalil »

I tried the code on the link and played around to make it work, but didn't work for me.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Get the path of the installed WhatsApp software

Post by HansV »

I couldn't make it work consistently either.
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4931
Joined: 31 Aug 2016, 09:02

Re: Get the path of the installed WhatsApp software

Post by YasserKhalil »

Thanks a lot anyway ..Hope someone has experience at this aspect.