Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have an application that depends on the .NET framework and performs a check at startup to see if the framework is installed. On our client machines, this works fine, but on our servers that run Windows Server 2k3, the check fails. When we look at the environment variables, it correctly shows that the Windows directory is C:\Windows and we can see that .NET is correctly installed there, but the Windows API call (GetWindowsDirectory) from our application returns C:\Programs and Settings\[User Name]\Windows which is invalid and doesn't even exist. Is there something about Server 2k3 that would cause this kind of mis-reporting, or do I need to look elsewhere? Thanks.

share|improve this question
up vote 1 down vote accepted

You're better off reading from the SystemRoot environment variable instead of using the Windows API call. Try string WindowsDir = System.Environment.GetEnvironmentVariable ("SystemRoot"); and see how you get on with it.

If you're calling from native code char *WindowsDir = getenv ("SystemRoot"); is what you want.

share|improve this answer
This lets me return exactly what I want. The strange thing about my problem though is it was only happening when I was working with the servers through Remote Desktop. Connecting to them locally returns the correct values with my original method. – Tom Mar 4 '10 at 0:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.