Hi all!
I want to create a program auto install font for window
I have copy file to %windir%\fonts, so it's accept denie ...
Can not install any font, also file(font)is exist ...
This my code
[DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
int SumFileInstalled = 0;
try
{
string[] filePaths = Directory.GetFiles(textBox1.Text);
string pathWin = Path.Combine(System.Environment.GetEnvironmentVariable("windir"),"Fonts");
foreach (string temp in filePaths)
{
try
{
string fileName = System.IO.Path.GetFileName(temp);
string destFile = System.IO.Path.Combine(pathWin, fileName);
System.IO.File.Copy(temp, destFile,true);
int result = -1;
int error = 0;
result = AddFontResource(destFile );
error = Marshal.GetLastWin32Error();
if (result == 0)
SumFileInstalled++;
}
catch (Exception ex)
{
int result = -1;
int error = 0;
result = AddFontResource(temp);
error = Marshal.GetLastWin32Error();
if (result == 0)
SumFileInstalled++;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error system, please choose folder default - "+ ex.Message, "Error", MessageBoxButtons.OK);
}
MessageBox.Show(SumFileInstalled.ToString()+" : installed successfully.","The finish fonts.",MessageBoxButtons.OK);
plz help me!
i used VS2010, win7 Pro 32bit
Thanks all