Windows application data directory - windows

With the environment variable %allusersprofile% I can get the directory where common settings are stored. But most programs store their settings in the sub-folder "anwendungsdaten" (German, application data). Is there a way to get the direct path to this folder? The problem is that its name is language dependent.
Thanks.

Not sure about what programming language you're using, so I'll assume the basic Windows api. In XP you can call SHGetFolderPath with CSIDL_COMMON_APPDATA as a parameter. It looks like Vista and 7 have a new set of functions that do the same thing, you'd probably want to call SHGetKnownFolderPath.
In Windows Forms, you can use the Application.UserAppDataPath property.

I can't see any direct way to get hold of this information directly. If nothing else comes up, the only thing that comes to mind is something hacky that will probably work in 99% of all cases:
Take %USERPROFILE%
Take %APPDATA%
Take %APPDATA% and replace %USERPROFILE% by null. The "rest" should be "/Application Data" or "/Anwendungsdaten" or whatever
Take %ALLUSERSPROFILE%
Add the result of step 3. to it
You should end up with the correct, localized path to the "Appdata" directory of the "All users" profile.
Note: This is untested and I have little experience in this field. But it might work.

I'm not aware of any direct way to get it, but if language is your concern then you could grab the end of %APPDATA%, from the last '\' symbol to the end of the string, and append that to %allusersprofile%.

Related

hide directory in rails project

I have create a new directory with
FileUtils.mkdir_p 'backupFiles' unless File.exists?('backupFiles')
how ever i like this folder to be hidden from CL and within the text editor visualisation of the rails project.
Any hints or advise how to do so?
and if the folder is hidden would it still be accessible by my program ? (e.g. with FileUtils.cp_r "./app", "backupFiles/")
This will be hard to answer correctly without any clarification on what you mean by "hidden" (I would have asked that in a comment, but reputation you know). I'll try anyway.
What I understand is that your application creates a directory in your app directory that you don't want to see.
If you don't want to see it in the Finder/Nautilus/Windows Explorer, then the easiest way should be to name the directory beginning with period. For your example that would translate to:
FileUtils.mkdir_p '.backupFiles' unless File.exists?('.backupFiles')
This wouldn't affect the accessibility of that folder via the commandline or your app in any way. (Accept that it's name starts with a period obviously)
Maybe that might be possible using SELinux Extended Security Attributes but it sounds pretty hard to implement.
Take a look at this:
https://superuser.com/questions/738392/completely-hide-files-on-linux

User changeable shortcuts

I've created a simply toolbox/dashboard in Visual Studio Express in VB for my work that contains links to all of the software and shortcuts we use on a day-to-day basis (see the image below, company name/app names covered to protect the innocent :p)
This was originally created for just me, then I modified the code to work on my co-workers computer. The changes that needed modifying were the addresses for each of the apps. Say, for example, App 1 is directly on the C:\ drive for me, but for my co-worker it is buried in C:\Program Files\blah blah blah. I would have to go in and hard code that path for each and every differing app path, and then if something happens and the path changes, I have to recode it again before deploying it.
What I would like to do it something where the user can modify the path so all I have to do is deploy the executable and the user can modify the path on their own. What would be the best way to accomplish this? Would it be best to have the executable look for a text file to read from/write to? Is there an easier and more effective way to do this? I'm open to any suggestions at this point
If you shellexecute just the program name, it will be looked up in the AppPaths registry key. See HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths. Plus it will open anything. If you want to open a text file a.txt, register it as a.exe. Typing a will run the command (notepad c:\somewhere\a.txt).

Windows Location in hexadecimals?

I was going through the source code of a rainmeter skin and i could not understand :
TextShortcut1=Computer
TextShortcut2=Libraries
TextShortcut3=Internet
TextShortcut4=Media Player
TextShortcut5=Control Panel
TextShortcut6=Trash
TextShortcut7=ShutDown
TextPath1=::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
TextPath2=shell:Libraries
TextPath3=http://google.com
TextPath4=shell:MusicLibrary
TextPath5=::{21EC2020-3AEA-1069-A2DD-08002b30309d}
TextPath6=::{645FF040-5081-101B-9F08-00AA002F954E}
TextPath7=rundll32.exe user32.dll LockWorkStation
Can anyone tell me what
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
::{21EC2020-3AEA-1069-A2DD-08002b30309d}
::{645FF040-5081-101B-9F08-00AA002F954E}
these are
and also how can we get one of these for a specific location from our computer.
Those are CLSID (Windows Class Identifiers). Certain special folders within the operating system are identified by unique strings.
20D04FE0-3AEA-1069-A2D8-08002B30309D is My Computer
21EC2020-3AEA-1069-A2DD-08002b30309d is Control Panel
645FF040-5081-101B-9F08-00AA002F954E is Recycle Bin
Source:
http://www.sevenforums.com/tutorials/110919-clsid-key-list-windows-7-a.html
In response to the comment:
can i have Class Identifiers for any folder on Computer or is it just
the bunch of those.
There isn't much reason for you to add more clsids, since you can just go to other locations by typing the normal path. This is a set list that is in the registry somewhere for special folders that don't really have "paths" like C:\windows does.
what is "shell:Something" is it a cmd command or location
shell: is similar to above. It is a convenient way of accessing special folders. Here is a good site for a list: http://smallvoid.com/article/winnt-shell-keyword.html . It is more of a shortcut for Windows Explorer to access a specific location than it is a command. You cant use them in batch files as far as I know (no command line stuff).
what is %something% like %temp%
Those are environment variables. You can usually count on certain ones existing, but the user can change these. Here is a list of some more: http://en.wikipedia.org/wiki/Environment_variables#Microsoft_Windows
how do they all differ?
Well, basically, they are just different ways of accessing the same thing. Some things are more backwards compatible than others, so you have to make that choice when the time comes. If you know your app is going to be on Windows 7 and above, you can make use of some of the more convenient shell:something ones. But if it needs to run on Windows 2000, you might have to rely more on older stuff like environment variables. Environment variables can also be customized by the user.

Proper usage of the windows user profile directory

I need to create a directory inside a windows users 'home' directory (c:\Documents and Settings\someusername\ or c:\users\someusername\). This directory will exist permanently but will only contain temporary files.
What is is the best location for this directory within the users profile if I want to be a good citizen? I should note that my program will be run by (possibly) non-admin users and will only need access to their own profile, but they must have permission to create the folder.
Using My Documents\NameOfMyApp\ is possible I guess, but that seems intrusive.
Is there a better location for this type of data, and a specific MFC call to access it?
I'd consider using the AppData directory. You can get its location with SHGetSpecialFolderLocation passing it CSIDL_APPDATA; (or a number of alternatives -- nearly every version of Windows adds a new replacement for SHGetSpecialFolderLocation, SHGetSpecialFolderPath, or (often) both).
Take a look at the following win32 calls:
GetUserProfileDirectory
GetAllUsersProfileDirectory
GetDefaultUserProfileDirectory
You probably want to use GetUserProfileDirectory and put your data in a sub-directory with your appname.
You will definitely want to use the function because there is no "\documents and settings" folder on vista and up, they changed to it "\user".
Being a good application citizen, you should use:
[drive]:\Documents and Settings[username]\Application Data[AppName] or
[drive]:\Documents and Settings[username]\Local Settings\Application Data[AppName]
(On Vista and Win7, "Documents and Settings" is replaced, most sensibly with "Users")
The environment variable USERPROFILE will provide the, you guessed it, User Profile Path.
The TEMP path provides the path to the user's individual temp directory
If the temp files aren't user-specific, you could use C:\temp
EDIT: If you are to use a user-specific location, I highly recommend that you use the environment variables (USERPATH on XP and 2000) rather than hard-coding the paths.
-Waldo
P.S. Thank you for asking this. I see bad behaviour from Waaaay too many applications. The root of the C: drive is not where you should be dumping things! At the very least, (test for the presence of, creating if necessary, and) use C:\Temp.

Where you you store your setting.xml?

For several of our applications we use an application configuration file. It usually just stores some directory paths and a few universal settings. We usually save it in the application directory (C:/Program Files/MyAppName)
One problem we see is users want to edit this (from the application) while logged in as a user that doesn't have access to write to the directory. Our applications are commonly installed and initially configured as an admin, but mostly used by (several different) limited users.
Is there a good way to make the setting.xml file read/write accessible to all users? Or a good place to put it?
C:\Documents and Settings\All Users\Application Data\<Your App> might be a decent place to consider.
Pass CSIDL_COMMON_APPDATA to SHGetSpecialFolderPath to get the writable, shared root data directory. Given that you can create a directory for your company and application.
Application data folder or moving to registry.
How important is localization? If localization isn't a high priority, you can store the files in %allusersprofile%\Application Data\ - that's the appdata folder accessible to all user accounts, and will work regardless of where things are installed, but only on English operating system installs.
If you want to store a file in the local user's directory and give each user their own, you can use %appdata% - that one will be entirely localized. But, each user will need their own copy, so it won't work if you need a common configuration.
If you need it to both be common to all users, and be 100% localized, you need to do a bit more work. I tried to find something like %allusersappdata%, and while I can find references online to that string, I can't get it to work on my own system. The workaround I found was to pull up %appdata% to find the localized text for the words Application Data, then use that to browse to that subfolder under %allusersprofile% - a bit more complicated, but it's the most bulletproof way I can find to do it. Someone please correct me if there's a direct path you can use to get to that folder.
I would try this previous question.
Which says:
System.Environment.SpecialFolder.LocalApplicationData
If you are using .NET

Resources