473,766 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Installing Fonts programatically C#

I have a piece of C# code using ShellExecute API to install a TrueType
font on Windows XP. The font is installed correctly and is visible
with programs like WinWord. However, the font file seems to be locked
down and cannot be deleted by administrators, unless the machine is
rebooted.

The code is as below:

class Program
{
[DllImport("shel l32.dll", EntryPoint = "ShellExecu te")]
public static extern int ShellExecuteA(i nt hwnd, string
lpOperation, string lpFile, string lpParameters, string lpDirectory,
int nShowCmd);

static void Main()
{
string[] arr = Environment.Get CommandLineArgs ();
String FontPath = arr[1];
ShellExecuteA(0 , "open", FontPath, "", "", 0);
}
}

Any ideas what I am missing?
Dec 6 '07 #1
4 7949
It looks like you're opening the font, not installing it... I'm not sure...

"ganesh" <sg*******@gmai l.comwrote in message
news:c9******** *************** ***********@j20 g2000hsi.google groups.com...
>I have a piece of C# code using ShellExecute API to install a TrueType
font on Windows XP. The font is installed correctly and is visible
with programs like WinWord. However, the font file seems to be locked
down and cannot be deleted by administrators, unless the machine is
rebooted.

The code is as below:

class Program
{
[DllImport("shel l32.dll", EntryPoint = "ShellExecu te")]
public static extern int ShellExecuteA(i nt hwnd, string
lpOperation, string lpFile, string lpParameters, string lpDirectory,
int nShowCmd);

static void Main()
{
string[] arr = Environment.Get CommandLineArgs ();
String FontPath = arr[1];
ShellExecuteA(0 , "open", FontPath, "", "", 0);
}
}

Any ideas what I am missing?

Dec 6 '07 #2
Nick,

Thanks for the suggestion.

I redid my code using AddFontResource API, but the result is the same
as with ShellExecute. The font gets installed in both cases, but the
font file itself seems to be locked and cannot be deleted, unless the
machine is rebooted. Below is the modified code using AddFontResource
API:

class Program
{
[DllImport("gdi3 2", EntryPoint = "AddFontResourc e")]
public static extern int AddFontResource A(string lpFileName);

static void Main()
{
string[] arr = Environment.Get CommandLineArgs ();
String FontPath = arr[1];
AddFontResource A(DestinationFi le);
}
}
Dec 7 '07 #3
Ganesh,

This might be a stupid question, but you said that you run programs
after that use the font. Are the programs that are using the font still
running when you try and delete the font? If they are, then I can see that
would be the reason why they are not deleting, because they are in use.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"ganesh" <sg*******@gmai l.comwrote in message
news:70******** *************** ***********@n20 g2000hsh.google groups.com...
Nick,

Thanks for the suggestion.

I redid my code using AddFontResource API, but the result is the same
as with ShellExecute. The font gets installed in both cases, but the
font file itself seems to be locked and cannot be deleted, unless the
machine is rebooted. Below is the modified code using AddFontResource
API:

class Program
{
[DllImport("gdi3 2", EntryPoint = "AddFontResourc e")]
public static extern int AddFontResource A(string lpFileName);

static void Main()
{
string[] arr = Environment.Get CommandLineArgs ();
String FontPath = arr[1];
AddFontResource A(DestinationFi le);
}
}

Dec 7 '07 #4
Nick

I ran the applications like Winword to verify if the font is
recongnized. However, the font file is locked up even prior to running
any application.

Thanks
Ganesh
Dec 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2914
by: Dennis Hore | last post by:
I'm trying to install Nick Patavalis' ppgplot package on Mac OS X 10.3 with python 2.3. I first sent this message to Nick, but he said he doesn't have any experience with the Mac platform. after installing using python setup.py install (using Numeric; no error messages), and then in python trying >>> import ppgplot i get:
3
1918
by: weston | last post by:
I'm trying to install FontTools ("a library for manipulating fonts, written in Python") on a Win XP box, and I'm given a bit of pause that this process seems to require downloading some MS .NET framework packages -- at least, this is what the "setup.py" script has told when I've tried to run it: "error: The .NET Framework SDK needs to be installed before building extensions for Python."
4
11969
by: L | last post by:
Hi there, Does C# support OpenType fonts? My c# application is not recognizing OpenType fonts. Thanks, Lalasa.
4
6929
by: Johan | last post by:
Hi How would I go about installing a font file on WinXP? I have tried this and it won't get installed properly, private void installFont() { File.Copy( Application.StartupPath+"\\Lucon1.ttf", this.fontDir+"\\Lucon1.ttf", true );
1
2196
by: rsine | last post by:
I am interested in writing an application to install fonts on our web server. Currently, when the server is rebooted, one has to remember to run an asp page that has the code built into it to install the fonts. I would like to right a .Net program that runs at startup to do this. So far though, all I can find to do this are references to the PrivateFontCollection. This appears to make fonts available only to the application and not to...
1
1320
by: Willie jan | last post by:
Hi, i tried to install a font by using code like: res = CreateScalableFontResource(0, Fontlst.Item(i), Fontlst.Item(i), String.Empty) res = AddFontResource(Fontlst.Item(i)) That works fine when the pc does not reboot, however after a reboot these added fonts disappear.
0
1235
by: Lauren Wilson | last post by:
What is going on with this? We created an installer for Access 2003 Runtime using the P & D Wizard from Access 2003 Dev Extensions. It appeared to be fine but on some computers it simply hangs on "Installing fonts" and the Task Manager shows "not responding." Does anyone know what could be causing this? Thanks in advance for all responses.
11
20225
by: Don | last post by:
QUESTIONS: 1. Has anyone figured out how to successfully install the Office 97 Pro Service Release 2 patch in Vista? 2. Has anyone successfully installed an Office 97 Pro CD (SR2 version) in Vista? DETAILS: My setup: Dell Inspiron notebook with Vista Business edition My CD: Office 97 Professional (Service Release 1) Upgrade
2
2003
by: JamesB | last post by:
Hi all. I have a Winforms app that installs a service programatically (as opposed to using InstallUtil). If UAC on Vista is disabled, it works fine. Likewise, if the program is started by right-clicking and picking "Run as Administrator" it works (if UAC is enabled), but neither option is ideal. I suppose really I want UAC to pop up it's "do you want to allow this to happen" box when my code does its thing. Can anyone point me in the...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.