   Finding out where a program is installed
  How do you find out where in the hard disk a program is installed?I remember back when you downloaded a patch or something else that needed to know where another program was installed, it would ask you to enter in the path.Then, programs got smarter, and would somehow find the best candidate for where the program is installed, and simply ask you if it was correct.Ive even seen programs that just magically automatically know where the program is installed and dont even have to ask you. I want to know how to do this. For example, with Winamp: How would I write a program or script that finds out where on the disk(s) winamp is installed. Sure I could just assume that its in the default path (C:\program files\winamp) But this is a very bad idea obviously, because a lot of people like to install winamp into a different path than this. Besides, depending on the version of winamp, this might not be correct anyway. For example, for Winamp version 3, its C:\program files\winamp3  .Thanks ![edited by - AndreTheGiant on February 12, 2004 5:08:10 PM]
  query the correct registry key containing the path infomationthats how all modern automagic patchers work ;  Many programs (in Windows) use the registry to store the path.  When the installation occurs, a key is stored in the registry.  Then the program can use that key to know where it is at later times (uninstalling, etc.).  As far as how to actually add things to the registry in your code, I don''t know how yet.   Tadd- WarbleWare ;  Hmm registry eh? I suspected as much.How do you know what to query? Should I just query for "winamp"? Or should I look for "winamp3"? That would assume that people are running version 3 though. And what if a version 4 or 5 comes out?  ;  If you''re building something to work with Winamp and want to be compliant with all versions, you''ll have to check each version and see what registry keys they use.  Then you''d have logic in your code to check all those spots and determine where they have it installed.  If they release a new version and put it in a completely new spot you''d have to release a new version too.  It may be simple if they always use the same key for all versions.Even if they change the key every version, you could probably use some guessing to try to find future version keys (based on how they''ve named them in the past).  But it wouldn''t be 100% since you never know what they might do.There may be other ways of doing this also if you are only working with one particular program and you know how it works.  Maybe winamp has something built in that contains it''s working directory that you could somehow access. (for example - though unlikely, maybe running winamp -d returns the install dir).  Or maybe winamp always uses some resource that you could use to track to the install directory.  But those would just be special cases if the software (winamp) happened to have something built into it already that you could use.  The registry is probably the best bet.   Tadd- WarbleWare ;  Hmm that whole "check each version and see what registry keys they use" sounds like a huge hassle. WOuldnt that involve finding all back versions of winamp (assuming theyre still available somewhere), and installing each of them, and then seeing what they do in the registry? Wow thats crazy.  Are you sure that is the best/only way to do it? quote:Original post by reana1  Maybe winamp has something built in that contains it''s working directory that you could somehow access. (for example - though unlikely, maybe running winamp -d returns the install dir). LOL wouldnt you have to know the install dir before running winamp -d to find out the install dir? Anyway thanks for the reply, very informative.I guess what I need to do know is find out what code I need to write to mess with the registry (I would like to know both C++ and Perl code to do it.) ;quote:Original post by AndreTheGiant  quote:Original post by reana1   Maybe winamp has something built in that contains it''s working directory that you could somehow access. (for example - though unlikely, maybe running winamp -d returns the install dir). This isn''t Unix  Not everything is in $PATH (almost nothing, in fact) so you can''t run without knowing the install dir in the first place...and I seriously doubt WinAmp responds to -d.   ;quote:Original post by Promit  This isn''t Unix  Not everything is in $PATH (almost nothing, in fact) so you can''t run without knowing the install dir in the first place...and I seriously doubt WinAmp responds to -d.   Hehe - true.  I did try to cover my rear with "unlikely". One thing you could do is make the user specify the path. When you install your addon tool, just prompt user to find/enter path to Winamp.  Then it''s out of your hands, but leaves more room for user-error.   Tadd- WarbleWare ;  Yea maybe what I''ll end up doing is sort of a combo of the two. Ill mess around with the registry for a bit and see if there is a ''most likely'' install path or something. Then Ill ask the user what the install path is, and provide the ''most likely'' one as the default. ;  When i was writing a HL mod i used NSIS as the installer (the thing winamp uses), I wrote some NSIS Script to look at known keys in the registry to find the install path, if found i checked for the HL.exe, if found it set the install path to that dir, otherwise as you say a default path is a good wayAlso, the installer checked to make sure that the HL.exe was in the directory the user selected when installing to try and prevent user error 