473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Finding Font File Name by FontName in Windows Vista

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.Loc alMachine, 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;

}
Feb 18 '07 #1
5 3643
Hello BL,

Your implementation is obviously a hack that accesses internal Windows
system information directly, thereby relying on a specific layout of that
internal information. It seems understandable that such an approach could
break on a new version of Windows, that's why it's generally not
recommended to use such approaches. Your solution will incorporate either
rearchitecting your implementation, if possible, to find a compatible way
of doing the same thing - there may be some API you could use, for
instance - or finding out the details that make the hack work on Vista, too.

Glancing over your code, I can't really say what your problem is - the
registry location looks correct. You don't explain what the error is that
you're getting, which would of course be the basic information we'd need.
My personal guess is that you're trying to access the registry with full
permissions, and you're getting some sort of "access denied" error. Try
accessing the registry read-only, that should work for your purpose. But
without further information, of course I can't be sure there's nothing
else going wrong.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 18 '07 #2
Thanks for reply

yes, the error is access denied in the case of restricted user, admin user
can easly access the registery

so if you have any idea about access registry in read only mode or is there
any API to access the font file name by font name please let me know

it will will a great help to me.

Thanks again

BL
"Oliver Sturm" wrote:
Hello BL,

Your implementation is obviously a hack that accesses internal Windows
system information directly, thereby relying on a specific layout of that
internal information. It seems understandable that such an approach could
break on a new version of Windows, that's why it's generally not
recommended to use such approaches. Your solution will incorporate either
rearchitecting your implementation, if possible, to find a compatible way
of doing the same thing - there may be some API you could use, for
instance - or finding out the details that make the hack work on Vista, too.

Glancing over your code, I can't really say what your problem is - the
registry location looks correct. You don't explain what the error is that
you're getting, which would of course be the basic information we'd need.
My personal guess is that you're trying to access the registry with full
permissions, and you're getting some sort of "access denied" error. Try
accessing the registry read-only, that should work for your purpose. But
without further information, of course I can't be sure there's nothing
else going wrong.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 19 '07 #3
Hello BL,
>yes, the error is access denied in the case of restricted user, admin user
can easly access the registery

so if you have any idea about access registry in read only mode or is there
any API to access the font file name by font name please let me know

it will will a great help to me.
Hm. Now I found something interesting. I looked at pages in MSDN to find
how that read-only access worked again - I was sure I'd done it in the
past, but I wanted to refresh my memory - and suddenly I found that
read-only access is actually the default using the .NET registry API.

So I went ahead and copied your code from your original post and created
my own sample program to try things out - and the sample worked! I tried
it both with Administrator privileges (when running from VS on Vista) and
without (running as a "normal" user on Vista) and in both cases it worked
just fine.

So obviously this doesn't really solve your problem after all, as the
issue is not reproducible for me. Sorry... at least we've found that you
have a permission issue, now we just need to find the source of that...

Question: what about that user you're using? Working as that user, can you
run regedit and access the information manually?
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 19 '07 #4
Hello Oliver

thanks for being with me

did you tested it in ASP.net 2.0 ?

in windows application it is working fine here.

BL

The follwoing the complete function

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.Loc alMachine, 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;

}
"Oliver Sturm" wrote:
Hello BL,
yes, the error is access denied in the case of restricted user, admin user
can easly access the registery

so if you have any idea about access registry in read only mode or is there
any API to access the font file name by font name please let me know

it will will a great help to me.

Hm. Now I found something interesting. I looked at pages in MSDN to find
how that read-only access worked again - I was sure I'd done it in the
past, but I wanted to refresh my memory - and suddenly I found that
read-only access is actually the default using the .NET registry API.

So I went ahead and copied your code from your original post and created
my own sample program to try things out - and the sample worked! I tried
it both with Administrator privileges (when running from VS on Vista) and
without (running as a "normal" user on Vista) and in both cases it worked
just fine.

So obviously this doesn't really solve your problem after all, as the
issue is not reproducible for me. Sorry... at least we've found that you
have a permission issue, now we just need to find the source of that...

Question: what about that user you're using? Working as that user, can you
run regedit and access the information manually?
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 19 '07 #5
Hello BL,
>thanks for being with me

did you tested it in ASP.net 2.0 ?
No - didn't cross my mind :-)

I'm sure that can be the problem, but I'm no expert in ASP.NET. I know
that a lot of things have changed in ASP.NET 2 with regard to code access
security, and I found a summary here:
http://msdn2.microsoft.com/en-us/library/ms998326.aspx
This also includes instructions for measuring one's needed permission set,
so I guess you should be able to find the problem if you follow these
instructions for your application.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a...
0
by: John Hunter | last post by:
I would like to extract the font and family name from a TTF file. I have been looking at fontTools ttLib, which parses the ttf file and provides lots of helpful information, but cannot find the...
3
by: Andreas Jung | last post by:
Reportlab has some problems with creating PDFs from UTF8 encoded text. For this reason they are using a truetype font rina.ttf which looks *very ugly*. Does anyone know of a suitable free...
5
by: dixie | last post by:
I want to be able to set the font size and font type for text in a text box on a report using VBA. I wan't to be able to control it from a setting in a table. The problem is that I don't know the...
10
by: tshad | last post by:
I have a Datagrid with a column: <asp:HyperLinkColumn DataTextField="JobTitle" DataNavigateUrlField="PositionID" DataNavigateUrlFormatString="AddNewPositions.aspx?PositionID={0}"...
1
by: jjbutera | last post by:
I have a custom font installed on my machine, but I can't seem to use it with System.Drawing. Dim f As New Font("MyCustomFontName", 20, FontStyle.Regular) This just gives me the default of...
0
by: Andrus | last post by:
I created RDL file containing TextBox with constant text. I used the following code to find TextBox <Widthtag value. However textbox width is too large. How to find exact width of string for...
6
by: Smokey Grindle | last post by:
So back in the vista beta we were told start using Segoe UI as our GUI font... well what happens when we backport the app to XP? I don't want to change the font just for a different windows...
3
by: Phil Stanton | last post by:
Correct me if I'm wrong, but is it impossible to change the font in a report field when in print preview (MDE database) or can it only be done in design view in the MDB database. Part of my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.