Finding location of an executable in a windows machine?
tjreedy at udel.edu
Fri May 15 15:59:35 EDT 2009
nonsense at mynonsense.net wrote:
> My python script calls another windows program file. I have the path
> to that program hardcoded in it. Is there a way for python to
> automatically find the path to this program?
> testapp_path = "C:\\Program Files\\testapp\\version\\61\\"
> Or do i have to do a brute force approach to searching all drives/
> folders till it finds a path matching my program name?
Program Files directories are usually not part of the PATH environment
variable. A main program in Program Files is generally started by
clicking on: an icon that points to it, an entry in Start Menu, its
directory listing in Explorer, or a file whose extension is associated
with it. A subsidiary program is started by a main program that knows
where is it in relation to the main program.
If a program is registered when installed, then there will be a registry
key that is the same for all installations that points to its
installation-specific location. Python on Windows comes with a winreg
module for accessing the registry. You just need to find the key,
possibly using the regedit utility and its search function.
Terry Jan Reedy
More information about the Python-list