Groups | Blog | Home
all groups > dotnet sdk > june 2006 >

dotnet sdk : GetWindowsDirectory() in .NET


David Thielen
6/14/2006 2:03:02 PM
Hi;

What's the managed code way to get GetWindowsDirectory()?

And if I want the fonts directory, is it safe to always just add "\fonts" to
it?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
David Thielen
6/14/2006 3:58:02 PM
thank you

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



[quoted text, click to view]
David Thielen
6/14/2006 8:10:02 PM
Thank you. I can pass multiple directories so I think I'll use both methods
and if they differ, pass both.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



[quoted text, click to view]
Greg Young
6/14/2006 10:30:06 PM
I would personally recommend using the environment class for this.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemenvironmentclasstopic.asp

Cheers,

Greg Young
[quoted text, click to view]

Jesse Houwing
6/15/2006 12:46:47 AM
[quoted text, click to view]
You should be able to get the fonts directory location from the
following registry location:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders]
"Fonts"="C:\\WINDOWS\\Fonts"


David Thielen
6/15/2006 9:09:52 AM
If anyone else needs this:

// get it from the environment
String dir =
System.Environment.GetFolderPath(System.Environment.SpecialFolder.System);
dir += "\\..\\fonts";
dir = System.IO.Path.GetFullPath(dir);
count += registerDirectory(dir);

// get it from the registry
Microsoft.Win32.RegistryKey regKey =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
if (regKey != null)
{
Object obj = regKey.GetValue("Fonts");
regKey.Close();
if (obj instanceof String)
{
String dir2 = System.IO.Path.GetFullPath((String)obj);
if (! dir.toLowerCase().equals(dir2.toLowerCase()))
count += registerDirectory(dir2);
}
}
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Greg Young
6/15/2006 1:30:31 PM
The problem is that the registry solution may not work in version x of
windows. The purpose of the Environment class is that it abstracts this from
you.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

[quoted text, click to view]

AddThis Social Bookmark Button