Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find application

    I'm working behind an Access 97 database on a network.
    I'd like to be able to check the user's computer to see if certain applications are installed. If they're not, I will prompt them on how to get them.
    Any ideas?
    Please keep it simple or please spell it out, I'm pretty new to VBA.[img]/w3timages/icons/baby.gif[/img]

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find application

    Hi Bill,

    Maybe the simplest way would be to check whether the applications' "exe." files exist. There are a few different ways to search for files on a computer; an easy way was described by Geoff Whitfield in a recent post on another thread (you could substitute the path for the application file):

    <hr>You can check if a file exists by a "Dir" command:

    if Dir("c:mydocumentssomething.dot") <> "" then
    msgbox "something.dot exists"
    end if

    <hr>
    (although I do recommend starting all keywords with capitals <g>)

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    Your suggestion would be fine except that I cannot be sure that a given application was installed to its default directory. I was hoping for some way to search the hard drive or possibly the (Registry?) to locate the executable or if an executable is assigned to open a particular extension like ,.doc, .bmp, .dwg, etc.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find application

    <P ID="edit"><FONT SIZE=-1>Edited by Gary Frieder on 01/02/16 01:49.</FONT></P>The following example illustrates one way to search a drive for an executable, without first specifying its location (it will return the location information however):

    <pre>Sub FileSearchForEXE()
    Dim n As Long
    Dim strFoundList As String
    Dim FS As FileSearch
    Set FS = Application.FileSearch
    With FS
    .NewSearch
    .LookIn = "C:"
    .SearchSubFolders = True
    .FileName = "winword.exe"
    .Execute
    If .Execute > 0 Then
    For n = 1 To .FoundFiles.Count
    strFoundList = strFoundList & vbCr & .FoundFiles(n)
    Next n
    MsgBox strFoundList
    End If
    End With
    Set FS = Nothing
    End Sub
    </pre>

    Interestingly, although "C" drive is specified, this code searched both partitions (C and D) of my hard drive.

    Also by the way, this code can take a long time to run.

    [Just an added note (and to keep Chris G. happy): this sub could easily be turned into a function, where you pass it the name of the app's .exe file - this would be a better approach particularly if you were having it do multiple searches.]

    Hope this helps,
    Gary

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Find application

    You might want to include another note--you needed an application object library reference or an Office library reference set in Office 97 apps to use FileSearch. And it wasn't available from the Access 97 application library.
    Charlotte

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    >[Just an added note (and to keep Chris G. happy): this sub

    I saw that! We'll see you in my Files.dot template, once we've completed Utils.dot!

    Actually, I went and looked at my code there and it's close to identical to yours! We must have pasted from the same Help file (grin!). I have similar code in my Instl.dot, one of whose functions is to sniff out potentially conflicting templates during the installation process.

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    I appreciate the information. But I have the fastest computer in the office and it took almost 40 seconds just to find the Word.exe. I was hoping for something that could do 3 or 4 searches in the background while the form was loading. But this code will be useful for some other things I'm working on.
    I had to make an alteration to the code before it ran, the system would not accept the Dim FS As FileSearch and Set FS = Application.FileSearch, using With Application.FileSearch was OK. Was I doing something wrong?

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find application

    Bill,

    The length of time it takes to do the search is due to the fact that it's searching your entire hard drive - I bet your computer is not only the fastest, but also has the largest HD, no? <g>.

    The alteration you needed to make in the code probably relates to the point Charlotte made, which is that FileSearch was not fully/inconsistently implemented in some Office 97 apps/versions. The code I posted was dashed off using Word 2000 - I vaguely remembered having to do it a little differently in Word 97 but didn't check.

    Gary

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    Right all around. That translates to less than a second per gig search time. Not bad when you look at it that way.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    >ice and it took almost 40 seconds just to find the Word.exe.

    My experience too. I have code (Fun4X) that loads fonts and loads ICOn files for GUIs. Forty seconds is about par for the course. I have two 20G drives (24 2G partitions) on a 233MHz running the original Win95.

    Let me know if you find any background-file-locate process.

  11. #11
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    Got it! A friend of mine found this somewhere on the internet a while ago, but he knows less about coding than I do. And I have to admit, I know very little. [img]/w3timages/icons/baby.gif[/img]
    Sorry Chris if this isn't more along the lines of what you were looking for, but it works great for me. Except one thing, if the same application is installed in two different folders an the same hard drive, this code returns a null string. Do you know how to change that so it recognizes the existence of an application no matter how many instances occur?

    Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpdirectory As String, ByVal lpResult As String) As Long

    Private Const MAX_FILENAME_LEN = 256

    Public Function FindExecutable(s As String) As String
    Dim i As Integer
    Dim s2 As String

    s2 = String(MAX_FILENAME_LEN, 32) & Chr$(0)

    i = FindExecutableA(s & Chr$(0), vbNullString, s2)

    If i > 32 Then
    FindExecutable = Left$(s2, InStr(s2, Chr$(0)) - 1)
    Else
    FindExecutable = ""
    End If

    End Function

  12. #12
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    This is probably the easiest way:

    Private Function GetAppPath(ByVal strExecutable As String)
    'This function retrieves the full pathname of an
    'installed application from the Windows Registry
    On Error Resume Next
    Dim objFSO As Object, objShell As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    GetAppPath = objShell.RegRead("HKLMSoftwareMicrosoftWindowsCurr entVersionApp Paths" & strExecutable & "")
    If Not objFSO.FileExists(GetAppPath) Then GetAppPath = vbNullString
    Set objShell = Nothing
    Set objFSO = Nothing
    End Function


    Usage:

    Sub GetPath()
    Debug.Print GetAppPath("winword.exe")
    End Sub

  13. #13
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Find application

    Don,

    Just want to confirm that this works great - much faster to retrieve info from the Registry than to scan an entire hard drive.

    If we needed to find apps that might be on a hard drive, but not necessarily registered, then I guess we'd still be out in the cold - not clear from the original post which was required (i.e. how strictly was the term "installed" being used?).

    Can you point to any good sources of information for learning more about using the Scripting File System Object?

    Thanks,
    Gary

  14. #14
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    That's nice!

    It worked great for me.

    Any feedback?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  15. #15
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Massachusetts
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find application

    Don,
    Very nice piece of code. The only drawback I see is that a lot of users are disabling/renaming windows script, due to the proliferation of viruses that use it (Not taking a position either way on that issue [img]/w3timages/icons/smile.gif[/img]). But, if present, that code works well.

    With that in mind (and borrowing heavily from your concept), how about the following:

    <pre>Function strAppExists(ByVal strAppName As String)

    strAppExists = System.PrivateProfileString("", "HKEY_LOCAL_MACHINESoftware" _
    & "MicrosoftWindowsCurrentVersionApp Paths" & strAppName, "Path")

    End Function</pre>


    Will return either the app path, or "" if not found. It could then be called by something similar to:

    <pre>Function CheckApp()
    Dim strCheckApp, strAppName
    strAppName = "excel.exe"
    strCheckApp = strAppExists(strAppName)

    If strCheckApp = "" Then
    MsgBox UCase(strAppName) & " not found"
    Else
    MsgBox UCase(strAppName) & " found installed at " & strCheckApp
    End If

    End Function</pre>


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •