in Configurator/Base/Classes/Utilities.cs [391:457]
public static bool ExecutionIsFromMSI(Version version)
{
if (version == null)
{
return false;
}
var keyName = string.Format(REGISTRY_KEY_TEMPLATE, version.Major, version.Minor);
RegistryKey key = null;
try
{
// Get installation reg key.
key = Registry.LocalMachine.OpenSubKey(keyName);
if (key == null)
{
key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Win32.Is64BitOs
? RegistryView.Registry64
: RegistryView.Registry32).OpenSubKey(keyName);
}
if (key == null)
{
return false;
}
// Get registry key install location.
var installLocation = key?.GetValue<string>("Location");
if (string.IsNullOrEmpty(installLocation))
{
return false;
}
// Verify install location exists and has files. It's been identified that the server reg key will sometimes
// not be removed, hence it is better to also check for the path to exist.
if (!Directory.Exists(installLocation)
|| Directory.GetFiles(installLocation).Length == 0)
{
return false;
}
// Identify if exe is running from the MSI install location.
string assemblyInstallLocation = null;
#if DEBUG
assemblyInstallLocation = ConfigurationManager.AppSettings["installationDirectory"];
#else
var assembly = Assembly.GetExecutingAssembly();
var assemblyLocation = new DirectoryInfo(assembly.Location);
if (assemblyLocation.Parent == null
|| assemblyLocation.Parent.Parent == null)
{
return false;
}
assemblyInstallLocation = assemblyLocation.Parent.Parent.FullName;
#endif
var installLocationDirInfo = new DirectoryInfo(installLocation);
var assemblyInstallLocationDirInfo = new DirectoryInfo(assemblyInstallLocation);
return string.Compare(installLocationDirInfo.FullName.TrimEnd('\\'), assemblyInstallLocationDirInfo.FullName.TrimEnd('\\'), StringComparison.InvariantCultureIgnoreCase) == 0;
}
catch (Exception ex)
{
Logger.LogException(ex);
}
return false;
}