cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Randy40
Level 4

Finding %userprofile% folder

Hello, I am working on an InstallScript project, where I want to be able to remove a specific folder (if it exists) under a User's local home folder (on Vista systems). For example, if the folder C:\Users\\AppData\Local\VirtualStore\ exists, I want to be able to delete it. Is there some kind of command in InstallScript similar to %userprofile% that easily finds the User's local home folder? Any help would be greatly appreciated. Thanks.

Regards,

Randy
Labels (1)
0 Kudos
(3) Replies
DLee65
Level 13

I am not sure about the virtual store but the following helps us to find the ALLUSERS directory.


function SetCommonDocumentsDir (hMSI)
NUMBER nResult;
STRING strCommonDocumentsDir;
begin
nResult = SHFolder.SHGetFolderPathA(NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, strCommonDocumentsDir);
if nResult =0
then
MsiSetProperty(hMSI, "COMMONDOCUMENTS", strCommonDocumentsDir);
else
SprintfMsiLog("Failed to set path for COMMONDOCUMENTS. Return Value: %d", nResult);
endif;
end;


Here is the header info:
[code]
#ifndef CSIDL_COMMON_DOCUMENTS
#define CSIDL_COMMON_DOCUMENTS 0x002e // All Users\Documents
#endif

export prototype SetCommonDocumentsDir(HWND);
prototype NUMBER SHFolder.SHGetFolderPathA(HWND, //A handle to an owner window. This parameter is typically set to NULL
NUMBER, //A CSIDL value that identifies the folder whose path is to be retrieved.
NUMBER, //[in] An access token that can be used to represent a particular user.
NUMBER, //[in] The flags to specify which path is to be returned.
//It is used for cases where the folder associated with a CSIDL
//may be moved or renamed by the user.
//SHGFP_TYPE_CURRENT
// Return the folder's current path.
//SHGFP_TYPE_DEFAULT
// Return the folder's default path.
BYREF STRING);//[out] A pointer to a null-terminated string of length
//MAX_PATH which will receive the path. If an error occurs or S_FALSE
//is returned, this string will be empty.
[/code]

I am sure you can find the appropriate CSIDL value by searching MSDN for what you are looking for.
0 Kudos
Randy40
Level 4

This is perfect Dan, many thanks for your quick reply! And yes, I can likely find the CSIDL through MSDN. Cheers.

Randy
0 Kudos
Randy40
Level 4

Hello, for anyone that might catch this thread and is looking for other CSIDL values (and for those who don't know what a CSIDL is, basically it is a value that provides a way to identify folders [used frequently by apps] which can have different names on different systems), click here for a list on MDSN:

http://msdn2.microsoft.com/en-us/library/bb762494.aspx

Thanks again to Dan for his help.

Regards,

Randy
0 Kudos