Problem using System.Environment.SystemDirectory

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

Using vb.net 2.0 and trying to get the drive letter the OS is installed on,
so from a console app I'm trying this:

Dim systemDirectory As String = Environment.SystemDirectory

However, systemDirectory is coming up null. when I put a watch on
Environment.SystemDirectory, it says "Property evaluation failed."

But it works when I do this:

Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory)

it works which I dont understand. Any idea how I can get the first line
above to work?

Thanks.
 
Well, I found something. It works in the regualar app, but doenst work in
the console app where I need to test some code before putting it into the
real app.

any idea why it doesnt work as I would expect in the console app?

Thanks.
 
moondaddy said:
Well, I found something. It works in the regualar app, but doenst work in
the console app where I need to test some code before putting it into the
real app.

any idea why it doesnt work as I would expect in the console app?

Thanks.


moondaddy said:
Using vb.net 2.0 and trying to get the drive letter the OS is installed
on, so from a console app I'm trying this:

Dim systemDirectory As String = Environment.SystemDirectory

However, systemDirectory is coming up null. when I put a watch on
Environment.SystemDirectory, it says "Property evaluation failed."

But it works when I do this:

Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory)

it works which I dont understand. Any idea how I can get the first line
above to work?

Thanks.


Your code works fine for me in a console application, as it should. I would
suggest putting option strict on, just in case you don't have that. Also,
please try the following line:

Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System))

This is my prefered way of doing this, but it is just that, a preference.
It shouldn't really make a difference, to the best of my knowledge.
 
Hi,

Your codes also work in my side. It returns "C:\Windows\system32".

If you try to get other machine level variables via the Environment class,
do you get the correct values?

Dim systemDirectory As String = Environment.SystemDirectory
Dim machineName As String = Environment.MachineName
Dim userName As String = Environment.UserName
Dim currentDirectory As String = Environment.CurrentDirectory
Dim commandLine As String = Environment.CommandLine


Best regards,
Colbert Zhou([email protected], remove "online.")
 
Hello,

Is the issue resolved in your side? Any future assistance needed, please
feel free to update here.

Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
Hello,

Is the issue resolved in your side? Any future assistance needed, please
feel free to update here.

Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
Back
Top