2
我想檢查主軟件是否安裝,如果主軟件沒有安裝,然後中止安裝。檢查我得到的代碼VS2015 Visual Studio Insaller =>設置項目添加自定義動作
/// <summary>
/// To check software installed or not
/// </summary>
/// <param name="controlPanelDisplayName">Display name of software from control panel</param>
private static bool IsApplictionInstalled(string controlPanelDisplayName)
{
string displayName;
RegistryKey key;
// search in: CurrentUser
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
if (null != key)
{
foreach (string keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
}
// search in: LocalMachine_32
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
if (null != key)
{
foreach (string keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
}
// search in: LocalMachine_64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
if (null != key)
{
foreach (string keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
{
return true;
}
}
}
// NOT FOUND
return false;
}
但不知道該放哪裏以及在哪裏調用此函數。請幫幫我。
在此先感謝。