Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Installing fonts on a Vista Pc

Installing fonts on a Vista Pc

Scheduled Pinned Locked Moved C#
help
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Okultist
    wrote on last edited by
    #1

    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

    D O 2 Replies Last reply
    0
    • O Okultist

      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

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Do you have rights to access the Fonts folder? Which line throws the exception? That would help knowing where the problem is.

      जय हिंद

      L O 2 Replies Last reply
      0
      • D dan sh

        Do you have rights to access the Fonts folder? Which line throws the exception? That would help knowing where the problem is.

        जय हिंद

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.


        D 1 Reply Last reply
        0
        • L Luc Pattyn

          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.


          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          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";
          

          जय हिंद

          O 1 Reply Last reply
          0
          • D dan sh

            Do you have rights to access the Fonts folder? Which line throws the exception? That would help knowing where the problem is.

            जय हिंद

            O Offline
            O Offline
            Okultist
            wrote on last edited by
            #5

            Is there a fast way to have a look on the privileges an user has for a folder? the windows explorer should have a way look them up.

            1 Reply Last reply
            0
            • D dan sh

              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";
              

              जय हिंद

              O Offline
              O Offline
              Okultist
              wrote on last edited by
              #6

              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.

              D 1 Reply Last reply
              0
              • O Okultist

                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.

                D Offline
                D Offline
                dan sh
                wrote on last edited by
                #7

                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).

                जय हिंद

                1 Reply Last reply
                0
                • O Okultist

                  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

                  O Offline
                  O Offline
                  Okultist
                  wrote on last edited by
                  #8

                  I think its not possible to copy the Font file to the font-folder with out adminstrator status. so i decided to use an application manifest to run my program as a adminstrator on startup.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups