Torna al Thread

public static bool IsRegisterSvr32(string path) { bool result = false; string pathLower = path.ToLower(); Microsoft.Win32.RegistryKey ckey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\CLASSES\CLSID\"); if (ckey != null) { string[] subKeyNames = ckey.GetSubKeyNames(); int i = 0; while (!result && i < subKeyNames.Length) { //verifica che la DLL è registrata object obj = LeggiPrimoValore(@"SOFTWARE\CLASSES\CLSID\" + subKeyNames[i] + @"\InprocServer32\"); if (obj != null && obj.GetType() == typeof(string)) { string valore = ((string)obj).ToLower(); result = pathLower.Equals(valore); } //Verifica che la versione della dll sia quella corretta obj = LeggiPrimoValore(@"SOFTWARE\CLASSES\CLSID\" + subKeyNames[i] + @"\Version\"); if (result && obj != null && obj.GetType() == typeof(string) && System.IO.File.Exists(path)) { System.Diagnostics.FileVersionInfo info = System.Diagnostics.FileVersionInfo.GetVersionInfo(path); string valore = ((string)obj).ToLower(); string versione = info.FileMajorPart.ToString() + "." + info.FileMinorPart.ToString(); result = valore.Equals(versione); } i++; } } ckey = null; return result; } private static object LeggiPrimoValore(string chiave) { Microsoft.Win32.RegistryKey ckeyCLSID = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(chiave); object result = null; if (ckeyCLSID != null) { string[] valuenames = ckeyCLSID.GetValueNames(); if (ckeyCLSID.GetValueNames().Length > 0) { result = ckeyCLSID.GetValue(valuenames[0]); } } ckeyCLSID = null; return result; }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5