| Subject: Finding Font File Name by Font Name in Windows Vista |
| Group: microsoft.public.windows.developer.winfx.announcements |
| Date: 2/18/2007 3:08:07 AM |
| From: =?Utf-8?B?Qkw=?= [Email Address Protection] |
Hello friends In c# 2005 I have written a function to access "font file name" by "Font name" and it is working fine in all the windows version other than vista, in vista it is throughing an error so please help me how can i access font file name by font name in windows vista or what change i have to do in following function to get the solution my function source code is givin below - private static string GetFontFileName(String FontName) { String subKey = ""; if (GetOSVer() > 4) { subKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"; } else { subKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts"; } return GetRegisteryValue(Microsoft.Win32.RegistryHive.LocalMachine, subKey, FontName); } public static string GetRegisteryValue(RegistryHive registryHive, String subKey, string valueName) { String returnValue = ""; Microsoft.Win32.RegistryKey registryKeyParent = null; Microsoft.Win32.RegistryKey registryKeyChild = null; switch (registryHive) { case Microsoft.Win32.RegistryHive.ClassesRoot: registryKeyParent = Microsoft.Win32.Registry.ClassesRoot; break; case Microsoft.Win32.RegistryHive.CurrentConfig: registryKeyParent = Microsoft.Win32.Registry.CurrentConfig; break; case Microsoft.Win32.RegistryHive.CurrentUser: registryKeyParent = Microsoft.Win32.Registry.CurrentUser; break; case Microsoft.Win32.RegistryHive.DynData: registryKeyParent = Microsoft.Win32.Registry.DynData; break; case Microsoft.Win32.RegistryHive.LocalMachine: registryKeyParent = Microsoft.Win32.Registry.LocalMachine; break; case Microsoft.Win32.RegistryHive.PerformanceData: registryKeyParent = Microsoft.Win32.Registry.PerformanceData; break; case Microsoft.Win32.RegistryHive.Users: registryKeyParent = Microsoft.Win32.Registry.Users; break; } registryKeyChild = registryKeyParent.OpenSubKey(subKey); if (registryKeyChild != null) { object abc = registryKeyChild.GetValue(valueName); returnValue = registryKeyChild.GetValue(valueName).ToString(); } else { throw new Exception("Registery key not found"); } return returnValue; } |
| Back |