Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.