Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What paths are guaranteed to exist on a Windows Server 2008 R2 instance? A client is requiring that some instructions specify exact paths in all cases. (The person executing said instructions is not supposed to have to decide on any path themselves, even when the path makes absolutely no difference.) So I need to know what paths I can rely on to be there. It's fine with me if they involve environment variables, but they need to be variables guaranteed to hold an existing path. (That is, no modification to a path that doesn't exist possible.)

Or are there no guaranteed paths?

share|improve this question
    
To be honest, I'm hoping the answer is that there are none. Then I can respond to this by telling them they have to guarantee me some paths exist before I can make the change. –  jpmc26 Sep 5 '12 at 23:06
    
It is better to use environmental variables for paths rather than hard coded paths as some of the paths may change slightly, but the variable won't: technipages.com/list-of-windows-environment-variables.html –  MaQleod Sep 5 '12 at 23:10
    
Fair enough, but are they guaranteed to represent existing locations? –  jpmc26 Sep 5 '12 at 23:15
    
That is the point of environmental variables - a common variable name that holds specific details to the current system configuration. For instance, %HOMEPATH% will always point to the currently logged in user's home directory, this will always be a valid path. Better yet, that specific option will always be writable to the currently logged in user, so you won't have to worry about permissions getting in the way either (unlike if you chose %HOMEDRIVE%, where Group Policy may prevent a user from writing to). –  MaQleod Sep 5 '12 at 23:21
    
Yes, many of the various environmental variables that point to folders must exist in order for Windows to operate. –  afrazier Sep 5 '12 at 23:23

2 Answers 2

up vote 5 down vote accepted

You can use environmental variables. These are variables that the system uses and so they are required to be valid paths. They are also ones that will work across various Windows platforms, so even if the standard hard coded paths change, the path loaded into the variable by windows will remain valid.

%HOMEPATH% - points to the home directory of the currently logged in user. This path will always be writable to the user so you won't have permissions issues if the users will be installing the software themselves.

%HOMEDRIVE% - points to the drive that the system was installed on (usually C:, but can change). This is not the best option for installation, group policy often prevents users from writing here.

%PROGRAMFILES% - default program files folder, common place for installations.

share|improve this answer
2  
+1: %APPDATA% and %TEMP% are two good ones as well. :) –  Ƭᴇcʜιᴇ007 Sep 5 '12 at 23:29
    
Thank you. I will probably use HOMEPATH since the directory is intended for a user to place files in. –  jpmc26 Sep 5 '12 at 23:34

Use the SHGetSpecialFolderPath() Windows API to retrieve the path corresponding to any of the various special folder symbolic names. For example, calling it on CSIDL_DESKTOPDIRECTORY guarantees to give you the localized name of the user's desktop directory. I used this API to build the directory utility included with my Hamilton C shell which, in turn, I use to know where to put things during installation.

share|improve this answer
    
Useful, but unfortunately, this is going in a document, not code. (Hence why I asked on Super User instead of StackOverflow.) Thanks, though. Hm. Some documentation says that method is unsupported and to use ShGetFolderPath instead. Does that work just as well? –  jpmc26 Sep 7 '12 at 0:05
1  
I'll be darned. I wrote my code using SHGetSpecialFolderPath() ten years ago on Win2K. It was definitely documented as supported then and no matter what the docs say today, it's still works on Win7. But it does look like MS would like us to migrate to their newer API, SHGetKnownFolderPath(). Thanks for picking that out. –  Nicole Hamilton Sep 7 '12 at 14:31

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.