المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Installing fonts on a Vista Pc



C# Programming
06-16-2009, 04:23 PM
I want to copy a font file to the fonts directory on windows vista, but currently i fail to get the right permissions.
Everytime I try to copy the font from its current folder to the font-directory (c:\windows\fonts) I get an "UnauthorisedAccessException"

My code looks like this at the moment:


if (System.IO.File.Exists(fontPath))
{
FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, "C:\\Windows\\Fonts\\");
f2.AddPathList(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, fontPath);

if (SecurityManager.IsGranted(f2) == true)
MessageBox.Show("Its fine!!");
else
MessageBox.Show("No Permissions");

try
{
f2.Demand();
MessageBox.Show(fontPath);
System.IO.File.Copy(fontPath, destination);
//AddFontResource(fontPath);
//SendMessage(HWND_BROADCAST, WM_FONTCHANGE, (IntPtr)0, (IntPtr)0);

}
catch (SecurityException se)
{
MessageBox.Show(se.ToString());
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show(ex.ToString());
}

}


Thanks for your help