How to get the full path of an existing file?

I want to shell an exe application from my visual basic application. When I run the shell command everything is working fine. But in my clients pc's that exe file may be anywhere(because while installing that program he can choose any folder). So I want to check where the file is and get the full path and shell this one. Suppose if he has c and d drives and the exe is in D drive, how to consider this case?

Any help,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How about storing in the registry the path to where you can find the file? This to be able to find the file quickly, instead of scanning thru all the harddrives. ;)
mskannanAuthor Commented:

hi vbmaster,
how to implement this?
i know we can use savesetting, getsetting apis but where to write this apis?
whether i have to write when the application first starts or during the installation of the software.
can you help?

It's SaveSetting and GetSetting, they are in the helpfiles (they are not API's but built in standard VB). What version of VB do you have? These are from VB5 and up, don't know about the earlier versions.

".. i have to write when the application first starts .."

Humm does this work, because as I understand it the user doesn't start this instead it's only executed via your other program. If this is the case it will be hard to execute the program first and THEN get the full filepath (where did it get it to execute it the first time? ;)).

".. or during the installation of the software .. "

This does sound like the best solution. You need to save the value in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\your_program_name_here\ to be able to use the SaveSetting/GetSetting statements.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mskannanAuthor Commented:
hi vbmaster,
how to call this function while setting up and not otherwise.

You mean that you want to save the value the first time the program executes? One solution would be to use the GetSetting function and if this returns a empty string/empty value or whatever it does when there is no such key, then just use SaveSetting to put in the filename there.
i think u whant to know the path of your  exe  Application ,how about app.path it will give u the Full path of your application

x = app.path
mskannanAuthor Commented:
hi hatem72,
I can use app.path if i want to know the path of the exe I am running. But now what i want is, from my application I want to find some other exes full path (for example, where notepad.exe is in the user's system)
Try this code...

Function GetAppPath(EXEName As String) As String
    Dim a As Long
    Dim i As Integer
    Dim sWordPath As String
    Dim sLen As Long
    GetAppPath = EXEName
    sWordPath = Space(256)
    a = RegQueryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" & EXEName, sWordPath, Len(sWordPath))
    If a = 0 Then
        For i = 1 To Len(sWordPath)
            If Asc(Mid(sWordPath, i, 1)) = 0 Then
                GetAppPath = Left(sWordPath, i - 1)
                Exit For
            End If
        Next i
    End If

End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mskannanAuthor Commented:

Your answer is excellant. Working for me fine. Only one glitch is that it works for only exes under Microsoft program group.
I tried changing the following line

"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"


and tried running this function which gives an error message. Anyway for me,
winword.exe is enough.

Thank you very much,
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.

This is the Community Support link, if help is needed, along with the link to All Topics since many new ones were recently added.
Moderator @ Experts Exchange
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.