Application path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mihail
    Contributor
    • Apr 2011
    • 759

    Application path

    Hi all !

    Many applications can be installed in a chosen folder (not necessary in C:\ProgramFiles \).
    The question is:
    Is it possible to find the path where a certain application is actually installed ?

    A pseudo code to be more clear what I am looking for:
    Code:
    Sub CallTest
    Dim strAppPath As String
        strAppPath = FindApplicationPath("Photoshop")
        MsgBox(strAppPath)
    End Sub
    
    Function FindApplicationPath(strAppName As String) As String
        'Code I am looking for
    End Function

    Thank you !
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Most programs will have a key in the registry, you can look in there to find it.

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      Thank you, Rabbit for the reply.
      But how to "look in" from VB ?
      The goal is to open a file (MyPic.jpg as example) but not using the default application ("Painter" also as example) but by using Photoshop or CorelDraw or PowerPoint or something else.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You can use VB can access the registry.

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          No need to use the registry.
          To load the settings for a program with the file in the path of the program:

          Code:
             Open App.PATH & "\settings.ini" For Input As #FNum

          Comment

          • Mihail
            Contributor
            • Apr 2011
            • 759

            #6
            Thank you for reply, Guido
            Your answer don't seems to fit my question.
            I suspect my poor English so please be patient and allow me to try explain again.

            Say I am the developer and you are the final user.
            My program must be able to open a file (say a .jpg file) using your Photoshop. But your Photoshop can be anywhere in your computer. Say you have the Photoshop installed in F:\PainterTools \Adobe\Photosho p 7.0
            More than, your default pictures editor is not the Photoshop.

            So, the question is:
            How can my code to find where the Photoshop is installed in your computer ?
            Please, see again the pseudo code from my first post.
            It is exactly what I am looking for.

            @Rabbit
            Sorry but i don't understand: I can or I can't use VBA to access the registry ?

            Comment

            • Guido Geurs
              Recognized Expert Contributor
              • Oct 2009
              • 767

              #7
              Sorry for the misunderstandin g.
              You can use "ShellExecu te" to open any file.
              ShellExecute recognize the extension and opens the according program if the extension is set in the windows "File Types" in the registry in the "HKEY_CLASSES_R OOT".
              This is always the default program for that type of file!
              This demo opens VB6 with the name ending on (*.vbp) = "E:\xfer7\B asic API Coder\CodeOptio nCreator.vbp"

              Code:
              Option Explicit
              
              Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
              
              Const SW_SHOW = 5
              
              Private Sub Command1_Click()
              Dim FILENAME As String
                 FILENAME = "E:\xfer7\Basic API Coder\CodeOptionCreator.vbp"
                 ShellExecute Me.hwnd, "open", FILENAME, vbNullString, vbNullString, SW_SHOW
              End Sub
              If you want to use an other program than the default, ask the user to enter the path to that program (use commondialog to browse to the path) and save it in a "settings" file or the registry.

              Comment

              • Mihail
                Contributor
                • Apr 2011
                • 759

                #8
                @Guido Geurs
                "...and save it in a "settings" file or the registry"


                That means that I can write in registry from VB.
                If I can write of course I can read from the registry.
                If I can read from registry I think that I can find the answer for my question.

                But I don't know how to open the registry file and where to look in for paths of installed programs.
                If this "new" questions needs new threads inform me please.

                I wish to thank you very much for help.
                I already have the code that allow me to open any file with any application IF I know the path to the file that launches that application (i.e Photoshop.exe)

                Also I know that I can ask the user for the path.
                But not any user can answer to this question.
                This is the main reason to try to find a programmaticall y solution.

                Thank you again !

                Comment

                • Guido Geurs
                  Recognized Expert Contributor
                  • Oct 2009
                  • 767

                  #9
                  This will read the "Shell-Open-Command" key in the registry (used to open an program).
                  You need to know the default key name of your program!
                  For you I think it will be something like:

                  HKEY_CLASSES_RO OT\Photoshop\sh ell\open\comman d

                  For winzip it's=
                  HKEY_CLASSES_RO OT\WinZip\shell \open\command

                  The value of the key =
                  "C:\Program Files\WinZip\WI NZIP32.EXE" "%1"

                  We need the first part without the quotes!
                  Use the Split function to devide the key-value string with the quotes and use the second part= index 1

                  Code:
                  Private Sub Command1_Click()
                  Dim WSHELL As Object
                  Dim EXEPATH As String
                     Set WSHELL = CreateObject("WScript.Shell")
                     'Put the full Key path WITH THE BACKSLASH "\" AFTER THE PATH
                     EXEPATH = WSHELL.regread("HKEY_CLASSES_ROOT\WinZip\shell\open\command\")
                     MsgBox Split(EXEPATH, """")(1)
                  End Sub

                  Comment

                  • Mihail
                    Contributor
                    • Apr 2011
                    • 759

                    #10
                    Thank you again... and much more :) Guido.
                    I think that it is what I am looking for.
                    I'll try that and I'll return here to thanks again or... to ask more.

                    THANK YOU !

                    Comment

                    Working...