[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Get the path to Windows folder

hello everybody,
i know how to get paths to practically any system folder using Application and Enviroment but I got no idea how to get a path to a folder where your Windows installed.

On the most machines it'll be "C:\Windows" but on Win2000 for example it will be WINNT... that's why I need to get it programmatically

regards
0
Yurich
Asked:
Yurich
  • 6
  • 5
  • 3
  • +1
2 Solutions
 
cyberdevil67Commented:
Hi Yurich,
 environment variable is %System%

Cheers!
0
 
cyberdevil67Commented:
Yurich,
 
This is VB but I am sure you could conver this to c#

Dim asm As [Assembly]

For Each asm In AppDomain.CurrentDomain.GetAssemblies()

messagebox.show (Asm.FullName)

messagebox.show (Asm.Location())
0
 
cyberdevil67Commented:
Yurich,

Or

string MyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
YurichAuthor Commented:
%System% is C:\Windows\System32

string MyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
will return the path to your exe file (checked)

checking your vb way but i've already found how to do this ;)

How would i use an environment variable?
0
 
YurichAuthor Commented:
duh... my vb knowledge is progressing to zero, i just created a new vb project and copy-pasted your code in the on button click event and it didn't work...

the way i did it is:

DirectoryInfo dirInfo = new System.IO.DirectoryInfo( System.Environment.SystemDirectory );
string winFolder = dirInfo.Parent.FullName;

regards
0
 
Fahad MukhtarDistinguished EngineerCommented:
Simply call one line code.. the easiest way perhaps:
MessageBox.Show(Environment.GetEnvironmentVariable("Windir"));
0
 
NipNFriar_TuckCommented:
Yurich you can doe that in C# also...

in C# the VB code looks like...

            DirectoryInfo di = new DirectoryInfo( Environment.SystemDirectory );
            MessageBox.Show( di.Parent.FullName );


Of course this is assuming that you have a

using System.IO;

statement in you file...

0
 
YurichAuthor Commented:
2NipNFriar_Tuck
How's your code is different from what I posted???
0
 
NipNFriar_TuckCommented:
It is not... I was simply pointing out that it could be done in C# and not just VB...
0
 
YurichAuthor Commented:
and mine was in VB you think??
0
 
NipNFriar_TuckCommented:
When you made the statement:

==> duh... my vb knowledge is progressing to zero, i just created a new vb project and copy-pasted your code in the on button click event and it didn't work...

Yes, I thought you were in VB...
0
 
YurichAuthor Commented:
i was talking about this stuff from the posting above:

Dim asm As [Assembly]

For Each asm In AppDomain.CurrentDomain.GetAssemblies()

messagebox.show (Asm.FullName)

messagebox.show (Asm.Location())


and the stuff below was what I used instead of the stuff above and it was c#
0
 
cyberdevil67Commented:
Yurich,

The link I posted does the system variables did that not work?
0
 
YurichAuthor Commented:
thanks guys for your help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now