tags:

views:

415

answers:

5

Is there a .net variable that returns the "All Users" directory?

A: 

I'm not sure if there is an environment variable for it, but I am sure I have seen it done somewhere before using the registry.. You will obviously need permissions to do that though!

I'll Google, BRB! :D

Rob Cooper
+7  A: 

[Major Edit]

You'll want to use the system.environment variables. Most of the predefined ones are shown here. For the "All Users" you would use

System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE")

I know I got a lot of upmods and a correct answer for my other stuff, but this actually works. where as the other environment variables I linked to previously don't seem to work with that function call.

Kibbee
A: 

@Nick isnt that the shared AppData path though? (Not the actual "root" of all users?)

I think the structure is always the same, so I guess you could traverse from there?

Rob Cooper
+1  A: 

Or,

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

You can then pass this result to System.IO.Directory.GetParent() to get the root "All Users" folder.

Peter Meyer
beware: on Win7 CommonApplicationData points to C:\ProgramData
Patrick Klug
+1  A: 

Is this any use?

Oops:

http://msdn.microsoft.com/en-us/library/bb774096(VS.85).aspx

Remou