[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to get the full path of an existing file?

Posted on 1999-11-18
10
Medium Priority
?
232 Views
Last Modified: 2013-12-25
hi,
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,
mskannan
0
Comment
Question by:mskannan
10 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2219964
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. ;)
0
 

Author Comment

by:mskannan
ID: 2221449

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?

mskannan.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2221517
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:mskannan
ID: 2221569
hi vbmaster,
how to call this function while setting up and not otherwise.

mskannan.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2221583
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.
0
 
LVL 6

Expert Comment

by:hatem72
ID: 2221834
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
0
 

Author Comment

by:mskannan
ID: 2223901
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)
mskannan.
0
 
LVL 1

Accepted Solution

by:
LCP earned 400 total points
ID: 2224552
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
0
 

Author Comment

by:mskannan
ID: 2226966
Hi LCP,

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\"

into

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

Thank you very much,
mskannan
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6822171
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.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question