Installing fonts on a Vista Pc
-
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
-
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
-
Do you have rights to access the Fonts folder? Which line throws the exception? That would help knowing where the problem is.
जय हिंद
Hi, when I run code like that on Vista I am getting a DirectoryNotFoundException on C:\Windows\Fonts\ in the File.Copy() statement, although the folder is visible both in Windows Explorer and in Command Prompt, and I am running with admin privileges. :confused:
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Hi, when I run code like that on Vista I am getting a DirectoryNotFoundException on C:\Windows\Fonts\ in the File.Copy() statement, although the folder is visible both in Windows Explorer and in Command Prompt, and I am running with admin privileges. :confused:
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Do you have rights to access the Fonts folder? Which line throws the exception? That would help knowing where the problem is.
जय हिंद
-
Same code works for me in XP. I have the variables set as:
string fontPath = @"c:\\test.txt"; string destination = @"C:\\Windows\\Fonts\\test.txt";
जय हिंद
-
Yeah, the problem is that i am using vista and a few things changed there. There are new security rules and i tried to do it the "good" way by asking the system for permissions.
Well, in my case the code works perfect in Vista as well (running as Admin). In your case, I see that you are checking the permissions for the file and not the destination folder. You can check the rights for that directory using
DirectorySecurity
class (I have never used it, hence not sure).जय हिंद
-
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