473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Application path

759 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. Sub CallTest
  2. Dim strAppPath As String
  3.     strAppPath = FindApplicationPath("Photoshop")
  4.     MsgBox(strAppPath)
  5. End Sub
  6.  
  7. Function FindApplicationPath(strAppName As String) As String
  8.     'Code I am looking for
  9. End Function

Thank you !
Mar 16 '12 #1

✓ answered by Guido Geurs

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_ROOT\Photoshop\shell\open\command

For winzip it's=
HKEY_CLASSES_ROOT\WinZip\shell\open\command

The value of the key =
"C:\Program Files\WinZip\WINZIP32.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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim WSHELL As Object
  3. Dim EXEPATH As String
  4.    Set WSHELL = CreateObject("WScript.Shell")
  5.    'Put the full Key path WITH THE BACKSLASH "\" AFTER THE PATH
  6.    EXEPATH = WSHELL.regread("HKEY_CLASSES_ROOT\WinZip\shell\open\command\")
  7.    MsgBox Split(EXEPATH, """")(1)
  8. End Sub

9 4967
Rabbit
12,516 Expert Mod 8TB
Most programs will have a key in the registry, you can look in there to find it.
Mar 16 '12 #2
Mihail
759 512MB
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.
Mar 16 '12 #3
Rabbit
12,516 Expert Mod 8TB
You can use VB can access the registry.
Mar 16 '12 #4
Guido Geurs
767 Expert 512MB
No need to use the registry.
To load the settings for a program with the file in the path of the program:

Expand|Select|Wrap|Line Numbers
  1.    Open App.PATH & "\settings.ini" For Input As #FNum
Mar 17 '12 #5
Mihail
759 512MB
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\Photoshop 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 ?
Mar 17 '12 #6
Guido Geurs
767 Expert 512MB
Sorry for the misunderstanding.
You can use "ShellExecute" 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_ROOT".
This is always the default program for that type of file!
This demo opens VB6 with the name ending on (*.vbp) = "E:\xfer7\Basic API Coder\CodeOptionCreator.vbp"

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. 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
  4.  
  5. Const SW_SHOW = 5
  6.  
  7. Private Sub Command1_Click()
  8. Dim FILENAME As String
  9.    FILENAME = "E:\xfer7\Basic API Coder\CodeOptionCreator.vbp"
  10.    ShellExecute Me.hwnd, "open", FILENAME, vbNullString, vbNullString, SW_SHOW
  11. 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.
Mar 18 '12 #7
Mihail
759 512MB
@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 programmatically solution.

Thank you again !
Mar 18 '12 #8
Guido Geurs
767 Expert 512MB
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_ROOT\Photoshop\shell\open\command

For winzip it's=
HKEY_CLASSES_ROOT\WinZip\shell\open\command

The value of the key =
"C:\Program Files\WinZip\WINZIP32.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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim WSHELL As Object
  3. Dim EXEPATH As String
  4.    Set WSHELL = CreateObject("WScript.Shell")
  5.    'Put the full Key path WITH THE BACKSLASH "\" AFTER THE PATH
  6.    EXEPATH = WSHELL.regread("HKEY_CLASSES_ROOT\WinZip\shell\open\command\")
  7.    MsgBox Split(EXEPATH, """")(1)
  8. End Sub
Mar 18 '12 #9
Mihail
759 512MB
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 !
Mar 18 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Paul Goods | last post by:
Hi, I have a class can be use by either Web Application or Window Application. Inside of this class, I need to get the application root. I know I can use...
2
by: Jim's wife | last post by:
How can I access the application path in access 2000? curdir shows me the documents abd settings directory. I want to be able to access the directory where my .mdb is put using code. Thanks
5
by: Frank Rizzo | last post by:
How to get Application Path? I can't really use System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase because it returns the path in the file://c/winnt/.../filename.exe format,...
8
by: Heidi Hundåla | last post by:
Hi ! I am trying to find the application path dynamically, meaning the place on disc where my web app is residing, like some function that returns "C:\Inetpub\wwwroot\MyApp\". Is there a...
7
by: Wim | last post by:
Hello, I'm looking for the C# equivalent of App.Path (that is the application path in Visual Basic). I think it is System.Security.Policy.ApplicationDirectory.Directory, but when I use this the...
3
by: ALI-R | last post by:
Hi The default direcoty when debugging the appication is always "...\myC#proramme\bin\Debug" and cuases problem because my xml files are in "...\myC#proramme" . Is there a way of getting the...
0
by: Arjen | last post by:
Hello, I have an ASP.NET web application on this place: C:\webapplications\portal\ Inside my C# class I tried to get the application path like this:...
3
by: Lal | last post by:
dear all, how can i defaine the application path to vb.net please help me --
1
by: Sep410 | last post by:
Hi, I wrote an application in windows form application and now they are telling me they need consol application instead of windows one. I never worked with consol application before.Here is my...
0
by: waynus62 | last post by:
Hi Whenever I try to use an openfiledialog I get the same issue. On my personal computer, it works fine... when launched on my work PC (Running XP), I can only view directories leading to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.