I'm calling vlc from a C# app in order to play a video. I need a way to consistently check if VLC is installed. I've tried checking registry keys, but they don't seem to be consistent or reliable 开发者_JAVA技巧depending on your Windows version or architecture. Anyone have any suggestions/advice?
I'd say you're doing unnecessary work in trying to detect this. What are you going to do if VLC is not installed? Show an error message? Then just try to launch it, and show an error message if it fails to launch. That way, you also capture the case where it is installed, but still fails to launch for whatever reason. Both are error conditions for your program.
Beyond that, make sure that you include a setup program with your application that automatically installs VLC, since your application requires it to work properly. Then, the only situation where it wouldn't be installed (and thus your application would have to show an error message) is if the user explicitly removes it after installation. Since they would have to do so intentionally, it's very unlikely they would be surprised when your application subsequently failed to work.
I ended up just checking HKLM\Software\VideoLAN\VLC\ on machines I could find it and giving the user an option in the settings to specify the path to VLC manually if it wasn't detected from that registry value.
精彩评论