简体   繁体   中英

C# find installation directory of application

I build an application that's run setup files and automatically patch it after setup completes.

I use this registry key HLKM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall but some applications doesn't have this key.

How I can find installation directory?

If you're using the VS Setup Project as your installer, then you can utilize Custom Actions as one method of getting information about the Setup environment.

With that said, I feel there might be a better way to accomplish your goals, and with more information I think we could help you get there.

EDIT

I think I follow you now. If I were doing this I would first hard code the default setup location for each 3rd party app I'm packaging. If the user changes the default, it won't be found, so then prompt them for their new path. Remember you can use Environment.SpecialFolder to get the actual location of Program Files (or other system folders), instead of assuming C:\\. For probably 99.9% of installations and users this method will complete without any extra user interaction.

Another option is to create your own installer for those 3rd party binaries that are being contrary. Of course you have to maintain updates too, but it sounds like you're already doing something like that with your patches.

You could use system and application classes.

Application.ExecutablePath

For example you can get the full name of the directory containing your executable as follows:

string executableName = Application.ExecutablePath;
FileInfo executableFileInfo = new FileInfo(executableName);
string executableDirectoryName = executableFileInfo.DirectoryName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM