Where can I find an include file for this function : SHGetKnownFolderPath ? It should be placed into shell32.
Idem for the KNOWNFOLDERID constants.
Thanks
i did a quick search for it and it's currently not defined. so you might have to declare it yourself
I made a call to LoadLibrary and GetProcAddress.
When The function returns it initializes EAX with 80070002h which seems to say "File not found" rather than INVALID_ARG !
I call the function like this
push OFFSET szResult
push -1
push 0
push OFFSET szGuId
call lpSHGetKnownFolderPath
I know that all the folders are not present onto my PC (I am running w7), but "My Documents" exists! So I don't understand; Can someone help me?
The GUID and corresponding CLSID can be found at http://phrio.biz/wiki/index.php?title=CLSID_%26_GUID
you may have the parameters out of order
also, i think FOLDERID_Documents is an equate - not a pointer to a string - i don't know what the value is
INVOKE SHGetKnownFolderPath,FOLDERID_Documents,<flags>,NULL,offset szPathString
insert the desired flags dword at <flags>
in INVOKE's, the last parm listed is the first parm pushed
push offset szPathString
push 0
push <flags>
push FOLDERID_Documents
call SHGetKnownFolderPath
I don't have Windows Vista. i am on Windows XP. i can show an example of SHGetFolderPath though :) or probably guess the code but cannot test it.
You could check the SHELL32.DLL exports with DumpPE, but according to this (http://www.geoffchappell.com/viewer.htm?doc=studies/windows/shell/index.htm) the function started with Vista, and I see no indication that it was exported by ordinal for the earlier versions.
The first parameter is not an equate. It is defined as a GUID (see the attached file).
http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx
Retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID.
Syntax
CopyHRESULT SHGetKnownFolderPath(
__in REFKNOWNFOLDERID rfid,
__in DWORD dwFlags,
__in HANDLE hToken,
__out PWSTR *ppszPath
);
Parameters
rfid [in]
REFKNOWNFOLDERID
A reference to the KNOWNFOLDERID that identifies the folder.
dwFlags [in]
DWORD
Flags that specify special retrieval options. This value can be 0; otherwise, one or more of the KNOWN_FOLDER_FLAG values.
hToken [in]
HANDLE
An access token that represents a particular user. If this parameter is NULL, which is the most common usage, the function requests the known folder for the current user.
Request a specific user's folder by passing the hToken of that user. This is typically done in the context of a service that has sufficient privileges to retrieve the token of a given user. That token must be opened with TOKEN_QUERY and TOKEN_IMPERSONATE rights. In addition to passing the user's hToken, the registry hive of that specific user must be mounted. See Access Control for further discussion of access control issues.
Assigning the hToken parameter a value of -1 indicates the Default User. This allows clients of SHGetKnownFolderPath to find folder locations (such as the Desktop folder) for the Default User. The Default User user profile is duplicated when any new user account is created, and includes special folders such as Documents and Desktop. Any items added to the Default User folder also appear in any new user account. Note that access to the Default User folders requires administrator privileges.
ppszPath [out]
PWSTR
When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the path of the known folder. The calling process is responsible for freeing this resource once it is no longer needed by calling CoTaskMemFree.
Return Value
HRESULT
Returns S_OK if successful, or an error value otherwise, including the following:
Return code Description
E_FAIL Among other things, this value can indicate that the rfid parameter references a KNOWNFOLDERID which does not have a path (such as a folder marked as KF_CATEGORY_VIRTUAL).
E_INVALIDARG Among other things, this value can indicate that the rfid parameter references a KNOWNFOLDERID that is not present on the system. Not all KNOWNFOLDERID values are present on all systems. Use IKnownFolderManager::GetFolderIds to retrieve the set of KNOWNFOLDERID values for the current system.
Remarks
This function replaces SHGetFolderPath. That older function is now simply a wrapper for SHGetKnownFolderPath.
Requirements
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
Shlobj.h
DLL
Shell32.dll (version 6.0.6000 or later)
Have you verified that the CLSID's you got from that webpage are the same ones defined in the MS headers?
http://www.abluestar.com/blog/get-special-folders-with-shgetknownfolderpath/
#include <shlobj.h>
void GetSpecialFolder( REFKNOWNFOLDERID rfid ) {
LPWSTR wszPath = NULL;
HRESULT hr = SHGetKnownFolderPath ( rfid, KF_FLAG_CREATE, NULL, &wszPath );
if ( SUCCEEDED(hr) )
{
wprintf( _T("Path: %s\n"), wszPath );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
GetSpecialFolder( FOLDERID_ProgramData ); // Shared program data directory for all users
GetSpecialFolder( FOLDERID_RoamingAppData ); // Per-user program data directory (roaming)
GetSpecialFolder( FOLDERID_LocalAppData ); // Per-user program data directory (non-roaming)
GetSpecialFolder( FOLDERID_ProgramFiles ); // App install directory
GetSpecialFolder( FOLDERID_Documents ); // Logs, reports, output
return 0;
}
Here is the MSDN page with the constant names, you would need to get the header file which defines the constants and convert it to MASM
http://msdn.microsoft.com/en-us/library/dd378457(v=VS.85).aspx
The function was introduced in Vista (according to MSDN) and either Vista or Server 2008 are the minimum OS requirement, as the supercedes SHGetFolderPath.
HR,
Ghandi
You can use the KnownFolders.h file from my header project and translate it to whichever assembler you use...
My Result :
Quote
; =========================================================================
.Data
ALIGN 4
; =========================================================================
KNOWNFOLDERID STRUCT
DWord_1 DWord ?
Word_1 Word ?
Word_2 Word ?
Byte_1 Byte ?
Byte_2 Byte ?
Byte_3 Byte ?
Byte_4 Byte ?
Byte_5 Byte ?
Byte_6 Byte ?
Byte_7 Byte ?
Byte_8 Byte ?
KNOWNFOLDERID ends
szSHGetKnownFolderPath Byte "SHGetKnownFolderPath",0
szShell32 Byte "Shell32.dll",0
;FOLDERID_ComputerFolder KNOWNFOLDERID <0AC0837Ch,0BBF8h,452Ah,85h,0Dh,79h,0D0h,8Eh,66h,7Ch,0A7h>
FOLDERID_NetworkFolder KNOWNFOLDERID <0D20BEEC4h,05CA8h,04905h,0AEh,03Bh,0BFh,025h,01Eh,0A0h,09Bh,053h>
FOLDERID_ComputerFolder KNOWNFOLDERID <00AC0837Ch,0BBF8h,0452Ah,085h,00Dh,079h,0D0h,08Eh,066h,07Ch,0A7h>
FOLDERID_InternetFolder KNOWNFOLDERID <04D9F7874h,04E0Ch,04904h,096h,07Bh,040h,0B0h,0D2h,00Ch,03Eh,04Bh>
FOLDERID_ControlPanelFolder KNOWNFOLDERID <082A74AEBh,0AEB4h,0465Ch,0A0h,014h,0D0h,097h,0EEh,034h,06Dh,063h>
FOLDERID_PrintersFolder KNOWNFOLDERID <076FC4E2Dh,0D6ADh,04519h,0A6h,063h,037h,0BDh,056h,006h,081h,085h>
FOLDERID_SyncManagerFolder KNOWNFOLDERID <043668BF8h,0C14Eh,049B2h,097h,0C9h,074h,077h,084h,0D7h,084h,0B7h>
FOLDERID_SyncSetupFolder KNOWNFOLDERID <0f214138h,0b1d3h,04a90h,0bbh,0a9h,027h,0cbh,0c0h,0c5h,038h,09ah> ;{0F214138-B1D3-4a90-BBA9-27CBC0C5389A}
FOLDERID_ConflictFolder KNOWNFOLDERID <04bfefb45h,0347dh,04006h,0a5h,0beh,0ach,00ch,0b0h,056h,071h,092h>
FOLDERID_SyncResultsFolder KNOWNFOLDERID <0289a9a43h,0be44h,04057h,0a4h,01bh,058h,07ah,076h,0d7h,0e7h,0f9h>
FOLDERID_RecycleBinFolder KNOWNFOLDERID <0B7534046h,03ECBh,04C18h,0BEh,04Eh,064h,0CDh,04Ch,0B7h,0D6h,0ACh>
FOLDERID_ConnectionsFolder KNOWNFOLDERID <06F0CD92Bh,02E97h,045D1h,088h,0FFh,0B0h,0D1h,086h,0B8h,0DEh,0DDh>
FOLDERID_Fonts KNOWNFOLDERID <0FD228CB7h,0AE11h,04AE3h,086h,04Ch,016h,0F3h,091h,00Ah,0B8h,0FEh>
FOLDERID_Desktop KNOWNFOLDERID <0B4BFCC3Ah,0DB2Ch,0424Ch,0B0h,029h,07Fh,0E9h,09Ah,087h,0C6h,041h>
FOLDERID_Startup KNOWNFOLDERID <0B97D20BBh,0F46Ah,04C97h,0BAh,010h,05Eh,036h,008h,043h,008h,054h>
FOLDERID_Programs KNOWNFOLDERID <0A77F5D77h,02E2Bh,044C3h,0A6h,0A2h,0ABh,0A6h,001h,005h,04Ah,051h>
FOLDERID_StartMenu KNOWNFOLDERID <0625B53C3h,0AB48h,04EC1h,0BAh,01Fh,0A1h,0EFh,041h,046h,0FCh,019h>
FOLDERID_Recent KNOWNFOLDERID <0AE50C081h,0EBD2h,0438Ah,086h,055h,08Ah,009h,02Eh,034h,098h,07Ah>
FOLDERID_SendTo KNOWNFOLDERID <08983036Ch,027C0h,0404Bh,08Fh,008h,010h,02Dh,010h,0DCh,0FDh,074h>
FOLDERID_Documents KNOWNFOLDERID <0FDD39AD0h,0238Fh,046AFh,0ADh,0B4h,06Ch,085h,048h,003h,069h,0C7h>
FOLDERID_Favorites KNOWNFOLDERID <01777F761h,068ADh,04D8Ah,087h,0BDh,030h,0B7h,059h,0FAh,033h,0DDh>
FOLDERID_NetHood KNOWNFOLDERID <0C5ABBF53h,0E17Fh,04121h,089h,000h,086h,062h,06Fh,0C2h,0C9h,073h>
FOLDERID_PrintHood KNOWNFOLDERID <09274BD8Dh,0CFD1h,041C3h,0B3h,05Eh,0B1h,03Fh,055h,0A7h,058h,0F4h>
FOLDERID_Templates KNOWNFOLDERID <0A63293E8h,0664Eh,048DBh,0A0h,079h,0DFh,075h,09Eh,005h,009h,0F7h>
FOLDERID_CommonStartup KNOWNFOLDERID <082A5EA35h,0D9CDh,047C5h,096h,029h,0E1h,05Dh,02Fh,071h,04Eh,06Eh>
FOLDERID_CommonPrograms KNOWNFOLDERID <00139D44Eh,06AFEh,049F2h,086h,090h,03Dh,0AFh,0CAh,0E6h,0FFh,0B8h>
FOLDERID_CommonStartMenu KNOWNFOLDERID <0A4115719h,0D62Eh,0491Dh,0AAh,07Ch,0E7h,04Bh,08Bh,0E3h,0B0h,067h>
FOLDERID_PublicDesktop KNOWNFOLDERID <0C4AA340Dh,0F20Fh,04863h,0AFh,0EFh,0F8h,07Eh,0F2h,0E6h,0BAh,025h>
FOLDERID_ProgramData KNOWNFOLDERID <062AB5D82h,0FDC1h,04DC3h,0A9h,0DDh,007h,00Dh,01Dh,049h,05Dh,097h>
FOLDERID_CommonTemplates KNOWNFOLDERID <0B94237E7h,057ACh,04347h,091h,051h,0B0h,08Ch,06Ch,032h,0D1h,0F7h>
FOLDERID_PublicDocuments KNOWNFOLDERID <0ED4824AFh,0DCE4h,045A8h,081h,0E2h,0FCh,079h,065h,008h,036h,034h>
FOLDERID_RoamingAppData KNOWNFOLDERID <03EB685DBh,065F9h,04CF6h,0A0h,03Ah,0E3h,0EFh,065h,072h,09Fh,03Dh>
FOLDERID_LocalAppData KNOWNFOLDERID <0F1B32785h,06FBAh,04FCFh,09Dh,055h,07Bh,08Eh,07Fh,015h,070h,091h>
FOLDERID_LocalAppDataLow KNOWNFOLDERID <0A520A1A4h,01780h,04FF6h,0BDh,018h,016h,073h,043h,0C5h,0AFh,016h>
FOLDERID_InternetCache KNOWNFOLDERID <0352481E8h,033BEh,04251h,0BAh,085h,060h,007h,0CAh,0EDh,0CFh,09Dh>
FOLDERID_Cookies KNOWNFOLDERID <02B0F765Dh,0C0E9h,04171h,090h,08Eh,008h,0A6h,011h,0B8h,04Fh,0F6h>
FOLDERID_History KNOWNFOLDERID <0D9DC8A3Bh,0B784h,0432Eh,0A7h,081h,05Ah,011h,030h,0A7h,059h,063h>
FOLDERID_System KNOWNFOLDERID <01AC14E77h,002E7h,04E5Dh,0B7h,044h,02Eh,0B1h,0AEh,051h,098h,0B7h>
FOLDERID_SystemX86 KNOWNFOLDERID <0D65231B0h,0B2F1h,04857h,0A4h,0CEh,0A8h,0E7h,0C6h,0EAh,07Dh,027h>
FOLDERID_Windows KNOWNFOLDERID <0F38BF404h,01D43h,042F2h,093h,005h,067h,0DEh,00Bh,028h,0FCh,023h>
FOLDERID_Profile KNOWNFOLDERID <05E6C858Fh,00E22h,04760h,09Ah,0FEh,0EAh,033h,017h,0B6h,071h,073h>
FOLDERID_Pictures KNOWNFOLDERID <033E28130h,04E1Eh,04676h,083h,05Ah,098h,039h,05Ch,03Bh,0C3h,0BBh>
FOLDERID_ProgramFilesX86 KNOWNFOLDERID <07C5A40EFh,0A0FBh,04BFCh,087h,04Ah,0C0h,0F2h,0E0h,0B9h,0FAh,08Eh>
FOLDERID_ProgramFilesCommonX86 KNOWNFOLDERID <0DE974D24h,0D9C6h,04D3Eh,0BFh,091h,0F4h,045h,051h,020h,0B9h,017h>
FOLDERID_ProgramFilesX64 KNOWNFOLDERID <06d809377h,06af0h,0444bh,089h,057h,0a3h,077h,03fh,002h,020h,00eh>
FOLDERID_ProgramFilesCommonX64 KNOWNFOLDERID <06365d5a7h,0f0dh,045e5h,087h,0f6h,0dh,0a5h,06bh,06ah,04fh,07dh>
FOLDERID_ProgramFiles KNOWNFOLDERID <0905e63b6h,0c1bfh,0494eh,0b2h,09ch,065h,0b7h,032h,0d3h,0d2h,01ah>
FOLDERID_ProgramFilesCommon KNOWNFOLDERID <0F7F1ED05h,09F6Dh,047A2h,0AAh,0AEh,029h,0D3h,017h,0C6h,0F0h,066h>
FOLDERID_AdminTools KNOWNFOLDERID <0724EF170h,0A42Dh,04FEFh,09Fh,026h,0B6h,00Eh,084h,06Fh,0BAh,04Fh>
FOLDERID_CommonAdminTools KNOWNFOLDERID <0D0384E7Dh,0BAC3h,04797h,08Fh,014h,0CBh,0A2h,029h,0B3h,092h,0B5h>
FOLDERID_Music KNOWNFOLDERID <04BD8D571h,06D19h,048D3h,0BEh,097h,042h,022h,020h,008h,00Eh,043h>
FOLDERID_Videos KNOWNFOLDERID <018989B1Dh,099B5h,0455Bh,084h,01Ch,0ABh,07Ch,074h,0E4h,0DDh,0FCh>
FOLDERID_PublicPictures KNOWNFOLDERID <0B6EBFB86h,06907h,0413Ch,09Ah,0F7h,04Fh,0C2h,0ABh,0F0h,07Ch,0C5h>
FOLDERID_PublicMusic KNOWNFOLDERID <03214FAB5h,09757h,04298h,0BBh,061h,092h,0A9h,0DEh,0AAh,044h,0FFh>
FOLDERID_PublicVideos KNOWNFOLDERID <02400183Ah,06185h,049FBh,0A2h,0D8h,04Ah,039h,02Ah,060h,02Bh,0A3h>
FOLDERID_ResourceDir KNOWNFOLDERID <08AD10C31h,02ADBh,04296h,0A8h,0F7h,0E4h,070h,012h,032h,0C9h,072h>
FOLDERID_LocalizedResourcesDir KNOWNFOLDERID <02A00375Eh,0224Ch,049DEh,0B8h,0D1h,044h,00Dh,0F7h,0EFh,03Dh,0DCh>
FOLDERID_CommonOEMLinks KNOWNFOLDERID <0C1BAE2D0h,010DFh,04334h,0BEh,0DDh,07Ah,0A2h,00Bh,022h,07Ah,09Dh>
FOLDERID_CDBurning KNOWNFOLDERID <09E52AB10h,0F80Dh,049DFh,0ACh,0B8h,043h,030h,0F5h,068h,078h,055h>
FOLDERID_UserProfiles KNOWNFOLDERID <00762D272h,0C50Ah,04BB0h,0A3h,082h,069h,07Dh,0CDh,072h,09Bh,080h>
FOLDERID_Playlists KNOWNFOLDERID <0DE92C1C7h,0837Fh,04F69h,0A3h,0BBh,086h,0E6h,031h,020h,04Ah,023h>
FOLDERID_SamplePlaylists KNOWNFOLDERID <015CA69B3h,030EEh,049C1h,0ACh,0E1h,06Bh,05Eh,0C3h,072h,0AFh,0B5h>
FOLDERID_SampleMusic KNOWNFOLDERID <0B250C668h,0F57Dh,04EE1h,0A6h,03Ch,029h,00Eh,0E7h,0D1h,0AAh,01Fh>
FOLDERID_SamplePictures KNOWNFOLDERID <0C4900540h,02379h,04C75h,084h,04Bh,064h,0E6h,0FAh,0F8h,071h,06Bh>
FOLDERID_SampleVideos KNOWNFOLDERID <0859EAD94h,02E85h,048ADh,0A7h,01Ah,009h,069h,0CBh,056h,0A6h,0CDh>
FOLDERID_PhotoAlbums KNOWNFOLDERID <069D2CF90h,0FC33h,04FB7h,09Ah,00Ch,0EBh,0B0h,0F0h,0FCh,0B4h,03Ch>
FOLDERID_Public KNOWNFOLDERID <0DFDF76A2h,0C82Ah,04D63h,090h,06Ah,056h,044h,0ACh,045h,073h,085h>
FOLDERID_ChangeRemovePrograms KNOWNFOLDERID <0df7266ach,09274h,04867h,08dh,055h,03bh,0d6h,061h,0deh,087h,02dh>
FOLDERID_AppUpdates KNOWNFOLDERID <0a305ce99h,0f527h,0492bh,08bh,01ah,07eh,076h,0fah,098h,0d6h,0e4h>
FOLDERID_AddNewPrograms KNOWNFOLDERID <0de61d971h,05ebch,04f02h,0a3h,0a9h,06ch,082h,089h,05eh,05ch,004h>
FOLDERID_Downloads KNOWNFOLDERID <0374de290h,0123fh,04565h,091h,064h,039h,0c4h,092h,05eh,046h,07bh>
FOLDERID_PublicDownloads KNOWNFOLDERID <03d644c9bh,01fb8h,04f30h,09bh,045h,0f6h,070h,023h,05fh,079h,0c0h>
FOLDERID_SavedSearches KNOWNFOLDERID <07d1d3a04h,0debbh,04115h,095h,0cfh,02fh,029h,0dah,029h,020h,0dah>
FOLDERID_QuickLaunch KNOWNFOLDERID <052a4f021h,07b75h,048a9h,09fh,06bh,04bh,087h,0a2h,010h,0bch,08fh>
FOLDERID_Contacts KNOWNFOLDERID <056784854h,0c6cbh,0462bh,081h,069h,088h,0e3h,050h,0ach,0b8h,082h>
FOLDERID_SidebarParts KNOWNFOLDERID <0a75d362eh,050fch,04fb7h,0ach,02ch,0a8h,0beh,0aah,031h,044h,093h>
FOLDERID_SidebarDefaultParts KNOWNFOLDERID <07b396e54h,09ec5h,04300h,0beh,0ah,024h,082h,0ebh,0aeh,01ah,026h>
FOLDERID_TreeProperties KNOWNFOLDERID <05b3749adh,0b49fh,049c1h,083h,0ebh,015h,037h,00fh,0bdh,048h,082h>
FOLDERID_PublicGameTasks KNOWNFOLDERID <0debf2536h,0e1a8h,04c59h,0b6h,0a2h,041h,045h,086h,047h,06ah,0eah>
FOLDERID_GameTasks KNOWNFOLDERID <054fae61h,04dd8h,04787h,080h,0b6h,09h,02h,020h,0c4h,0b7h,00h>
FOLDERID_SavedGames KNOWNFOLDERID <04c5c32ffh,0bb9dh,043b0h,0b5h,0b4h,02dh,072h,0e5h,04eh,0aah,0a4h>
FOLDERID_Games KNOWNFOLDERID <0cac52c1ah,0b53dh,04edch,092h,0d7h,06bh,02eh,08ah,0c1h,094h,034h>
FOLDERID_RecordedTV KNOWNFOLDERID <0bd85e001h,0112eh,0431eh,098h,03bh,07bh,015h,0ach,009h,0ffh,0f1h>
FOLDERID_SEARCH_MAPI KNOWNFOLDERID <098ec0e18h,02098h,04d44h,086h,044h,066h,097h,093h,015h,0a2h,081h>
FOLDERID_SEARCH_CSC KNOWNFOLDERID <0ee32e446h,031cah,04abah,081h,04fh,0a5h,0ebh,0d2h,0fdh,06dh,05eh>
FOLDERID_Links KNOWNFOLDERID <0bfb9d5e0h,0c6a9h,0404ch,0b2h,0b2h,0aeh,06dh,0b6h,0afh,049h,068h>
FOLDERID_UsersFiles KNOWNFOLDERID <0f3ce0f7ch,04901h,04acch,086h,048h,0d5h,0d4h,04bh,004h,0efh,08fh>
FOLDERID_SearchHome KNOWNFOLDERID <0190337d1h,0b8cah,04121h,0a6h,039h,06dh,047h,02dh,016h,097h,02ah>
FOLDERID_OriginalImages KNOWNFOLDERID <02C36C0AAh,05812h,04b87h,0bfh,0d0h,04ch,0d0h,0dfh,0b1h,09bh,039h>
; =========================================================================
.Code
ALIGN 16
; =========================================================================
;HRESULT SHGetKnownFolderPath(
; __in REFKNOWNFOLDERID rfid,
; __in DWORD dwFlags,
; __in HANDLE hToken,
; __out PWSTR *ppszPath
;);
SHGetKnownFolderPath PROC __rfid:DWord,__dwFlags:DWord,__hToken:HANDLE,__lpszPath:LPBYTE
LOCAL _dwResult:DWord
LOCAL _szTmp[1024]:Byte
LOCAL _lpszResult:LPWSTR
INVOKE LoadLibrary,ADDR szShell32
push eax
INVOKE GetProcAddress,eax,ADDR szSHGetKnownFolderPath
lea edx,_szTmp
mov DWord Ptr [edx],SIZEOF _szTmp
push edx
push __hToken
push __dwFlags
push __rfid
call eax
push edi
push esi
mov esi,DWord Ptr _szTmp
mov edi,__lpszPath
xor eax,eax
test esi,esi
jz @EndLoop
@Loop :
mov al,Byte Ptr [esi]
test al,al
jz @EndLoop
mov Byte Ptr [edi],al
add esi,2
add edi,1
jmp @Loop
@EndLoop :
mov Byte Ptr [edi],0
pop esi
pop edi
call FreeLibrary
mov eax,__lpszPath
ret
SHGetKnownFolderPath ENDP
; =========================================================================
It can be downloaded at : http://www.phrio.biz/Assembleur/SHGetKnownFolderPath.asm