Determining Path To A Separate Program

P

Phil Galey

In VB.NET, when you use shell or have a process object point to and run a
separate application that is installed on the machine, is there a way of
determining the path to the executable? I've been having the user point to
it using the Open File Dialog from an Options menu item, but the program
should be able to determine the path to a named program without relying on
user intervention.

Thanks.
 
S

Scott Swigart

Don't know if this is the best way, but you can just loop through the paths
in the PATH environment variable and look for the file in each one. Here's
a console app that does it:

Imports System.Environment
Imports System.IO

Module Module1

Sub Main()
Dim fileToFind As String = "Notepad.exe"
For Each pathName As String In
GetEnvironmentVariable("path").Split(";")
Dim fullPath As String = pathName & "\" & fileToFind
If File.Exists(fullPath) Then
Console.WriteLine(fullPath)
End If
Next

End Sub

End Module

- Scott Swigart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top