locked
Cannot Copy file to C:\Windows\ Fonts folder in win 7

    Question

  • I am trying to instal fonts in Windows 7 from an application, but when I run the code to copy the file to the Windows Font folder I get an 'Access Denied ' error. Can anyone tell me how to remedy this. The code I am using at the moment is as follows:

     

    Private Sub btnInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstall.Click

            Dim src As String = FontArray(lstFonts.SelectedIndex).ToString ' Gets full path of font file
            Dim fileName As String = GetFileName(src)
            Dim Dest As String = "C:\Windows\Fonts\" & fileName

            If Not src = "" Then
                Try
                    If My.Computer.FileSystem.FileExists(Dest) Then
                        Dim Result As DialogResult

                        Result = MessageBox.Show("A version of this file already exists at this" & vbCrLf _
                        & " location, do you wish to overwrite it ?", "File Exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

                        Select Case Result
                            Case Windows.Forms.DialogResult.Yes
                                My.Computer.FileSystem.CopyFile(src, Dest)
                            Case Else
                                Exit Sub
                        End Select
                    Else
                        My.Computer.FileSystem.CopyFile(src, Dest)
                    End If
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If

    End Sub

       Private Function GetFileName(ByRef fullPath As String) As String
            Return fullPath.Substring(fullPath.LastIndexOf("\") + 1)
        End Function

    I know I still have to use 'AddFontresource' to install the font but first I need to get the file into the font folder, which is proving to be a problem.

    Any help would be appreciated. Thanks.

    Monday, April 05, 2010 6:32 AM

Answers

  • Hi

    First, Shrikanth, I'm not sure exactly what you are asking but if you are having trouble getting UAC access I suggest you look at an article in Visual Studio magazine:

    http://visualstudiomagazine.com/articles/2007/11/01/banish-uac-issues.aspx

    It will explain how to elevate your application privileges.

     

    Secondly, Jeff, Thanks but I needed to install Fonts from my app. If anyone is interested, take a look at this Web article which explains how to do this:

    http://www.gamedev.net/community/forums/topic.asp?topic_id=386084

    In this article, The FONTS_FOLDER variable is the full path to the font file.

    This article helped me resolve my issues.

    Incidentally, part of my problem whilst trying to figure out how to install fonts was that after I had copied the font file to the fonts folder, it was not visible in my file managers even though my code was telling me it was there. I finally resolved this by using a file search app called 'Agent Ransack'. It found the file OK so I was able to see what was going on.

    I hope this helps someone.

    • Marked as answer by Trembru Sunday, April 18, 2010 9:13 AM
    Friday, April 16, 2010 10:24 PM

All replies

  • Try running your application as Administrator.
    Thanks,
    A.m.a.L
    [MVP Visual C#]
    Dot Net Goodies
    Don't hate the hacker, hate the code
    Monday, April 05, 2010 7:53 AM
  • This Appears to work but I cannot find the file where it is supposed to be, Even using a non microsoft file manager (Explorer2), the file does not appear in the fonts folder, though my Application tells me it is there if I try to copy again.

    Assuming this is a Win 7 quirk. How do I alter my code to invoke the UAC window when this copy function is used? to elevate privileges instead of Running the program as administrator?

    Thanks

    Trev.

    Monday, April 05, 2010 8:35 AM
  • Hello Trembru,

    I am facing  same issue like you . i am not able to select the fonts from designer application which are located in windows\fonts folder in windows 7.

    Eventhough i logged in as an Admin it  is  giving Previliges error.

    Any ideas??

    -regards,

    Shrikanth GC


    Thanks & regards, Shrikanth GC
    Friday, April 16, 2010 10:27 AM
  • best bet might be to look at using an installer which has the ability to install fonts.  you may be able to use vbscript as well.  something to look into.

    Peace


    FREE
    DEVELOPER TOOLS     CODE     PROJECTS

    DATABASE CODE GENERATOR
    DATABASE / GENERAL  APPLICATION TUTORIAL
    Upload Projects to share or get help on and post the generated links here in the forum
    www.srsoft.us
    Friday, April 16, 2010 5:10 PM
  • Hi

    First, Shrikanth, I'm not sure exactly what you are asking but if you are having trouble getting UAC access I suggest you look at an article in Visual Studio magazine:

    http://visualstudiomagazine.com/articles/2007/11/01/banish-uac-issues.aspx

    It will explain how to elevate your application privileges.

     

    Secondly, Jeff, Thanks but I needed to install Fonts from my app. If anyone is interested, take a look at this Web article which explains how to do this:

    http://www.gamedev.net/community/forums/topic.asp?topic_id=386084

    In this article, The FONTS_FOLDER variable is the full path to the font file.

    This article helped me resolve my issues.

    Incidentally, part of my problem whilst trying to figure out how to install fonts was that after I had copied the font file to the fonts folder, it was not visible in my file managers even though my code was telling me it was there. I finally resolved this by using a file search app called 'Agent Ransack'. It found the file OK so I was able to see what was going on.

    I hope this helps someone.

    • Marked as answer by Trembru Sunday, April 18, 2010 9:13 AM
    Friday, April 16, 2010 10:24 PM
  • Hi Trembru,

    I am having hard time copying a file to font folder in windows 7 using vb.net. My application runs with admin previlages. I have set UAC settings to ensure it. I have also put code to check elevated previlages. However, when I try copying (replacing) a file to fonts folder, I get access denied error. However, I could copy the file using scripting.filesystemobject. Can you share me your code. Thanks.

    Tuesday, July 17, 2012 5:43 PM