how to find the execution path of a installed software

后端 未结 6 1358
夕颜
夕颜 2020-12-05 16:26

How can i find the execution path of a installed software in c# for eg media player ,vlc player . i just need to find their execution path . if i have a vlc player install

6条回答
  •  佛祖请我去吃肉
    2020-12-05 17:04

    I used the CurrentVersion\Installer\Folders registry key. Just pass in the product name.

    private string GetAppPath(string productName)
        {
            const string foldersPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders";
            var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
    
            var subKey = baseKey.OpenSubKey(foldersPath);
            if (subKey == null)
            {
                baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                subKey = baseKey.OpenSubKey(foldersPath);
            }
            return subKey != null ? subKey.GetValueNames().FirstOrDefault(kv => kv.Contains(productName)) : "ERROR";          
        }
    

提交回复
热议问题