views:

725

answers:

2

We need to reliably get the Quick Launch folder for both All and Current users under both Vista and XP. I'm developing in C++, but this is probably more of a general Windows API question.

For reference, here is code to get the Application Data folder under both systems:

 HRESULT hres; 
 CString basePath;
 hres = SHGetSpecialFolderPath(this->GetSafeHwnd(), basePath.GetBuffer(MAX_PATH), CSIDL_APPDATA, FALSE);
 basePath.ReleaseBuffer();

I suspect this is just a matter of knowing which sub-folder Microsoft uses.

Under Windows XP, the app data subfolder is:

Microsoft\Internet Explorer\Quick Launch

Under Vista, it appears that the sub-folder has been changed to:

Roaming\Microsoft\Internet Explorer\Quick Launch

but I'd like to make sure that this is the correct way to determine the correct location.

Finding the correct way to determine this location is quite important, as relying on hard coded folder names almost always breaks as you move into international installs, etc... The fact that the folder is named 'Roaming' in Vista makes me wonder if there is some special handling related to that folder (akin to the Local Settings folder under XP).

EDIT: The following msdn article: http://msdn.microsoft.com/en-us/library/bb762494.aspx indicates that CSIDL_APPDATA has an equivalent ID of FOLDERID_RoamingAppData, which does seem to support StocksR's assertion that CSIDL_APPDATA does return C:\Users\xxxx\AppData\Roaming, so it should be possible to use the same relative path for CSIDL_APPDATA to get to quick launch (\Microsoft\Internet Explorer\Quick Launch).

So the following algorithm is correct per MS:

HRESULT hres; 
CString basePath;
hres = SHGetSpecialFolderPath(this->GetSafeHwnd(), basePath.GetBuffer(MAX_PATH), CSIDL_APPDATA, FALSE);
basePath.ReleaseBuffer();
CString qlPath = basePath + "\\Microsoft\\Internet Explorer\\Quick Launch";

it would also be a good idea to check hres to ensure that the call to SHGetSpecialFolderPath was successful.

+1  A: 

AppData on vista refers to C:\Users\xxxx\AppData\Roaming not the C:\Users\xxxx\AppData folder it's self.

Also this artical http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0901.mspx on a microsoft site implies that you simply have to use the path relative to the appdata folder

StocksR
A: 

Great question!

Whatever you do, don't give into the temptation to dig into the registry to find this info!

Also, we must resist the temptation to hard code some path, even partially. If we get the special AppData path, then simply append a string onto the end, this may break under non-US installs of the software where the folder name is localized to that language. E.g. GetSpecialFolderPath(APP_DATA) + "\\Fonts" will not work on non-English versions of Windows.

Hopefully someone has the proper answer to your question; I'm curious to know it myself!

Judah Himango