Get the location of special windows folder

Started by kevin, December 03, 2008, 05:40:41 PM

Previous topic - Next topic

kevin

 Get the location of special windows folder from PlayBASIC programs.


Related To:
Get Temp Folder of current Windows user


PlayBASIC Code: [Select]
// These constants can be passed into the GetSpecialFolderPath function to locate the required path on this system.


Constant CSIDL_DESKTOP = $0 ;{desktop}
Constant CSIDL_INTERNET = $1 ;Internet Explorer (icon on desktop)
Constant CSIDL_PROGRAMS = $2 ;Start Menu\Programs
Constant CSIDL_CONTROLS = $3 ;My Computer\Control Panel
Constant CSIDL_PRINTERS = $4 ;My Computer\Printers
Constant CSIDL_PERSONAL = $5 ;My Documents
Constant CSIDL_FAVORITES = $6 ;{user}\Favourites
Constant CSIDL_STARTUP = $7 ;Start Menu\Programs\Startup
Constant CSIDL_RECENT = $8 ;{user}\Recent
Constant CSIDL_SENDTO = $9 ;{user}\SendTo
Constant CSIDL_BITBUCKET = $A ;{desktop}\Recycle Bin
Constant CSIDL_STARTMENU = $B ;{user}\Start Menu
Constant CSIDL_DESKTOPDIRECTORY = $10 ;{user}\Desktop
Constant CSIDL_DRIVES = $11 ;My Computer
Constant CSIDL_NETWORK = $12 ;Network Neighbourhood
Constant CSIDL_NETHOOD = $13 ;{user}\nethood
Constant CSIDL_FONTS = $14 ;windows\fonts
Constant CSIDL_TEMPLATES = $15
Constant CSIDL_COMMON_STARTMENU = $16 ;All Users\Start Menu
Constant CSIDL_COMMON_PROGRAMS = $17 ;All Users\Programs
Constant CSIDL_COMMON_STARTUP = $18 ;All Users\Startup
Constant CSIDL_COMMON_DESKTOPDIRECTORY = $19 ;All Users\Desktop
Constant CSIDL_APPDATA = $1A ;{user}\Application Data
Constant CSIDL_PRINTHOOD = $1B ;{user}\PrintHood
Constant CSIDL_LOCAL_APPDATA = $1C ;{user}\Local Settings _
;\Application Data (non roaming)
Constant CSIDL_ALTSTARTUP = $1D ;non localized startup
Constant CSIDL_COMMON_ALTSTARTUP = $1E ;non localized common startup
Constant CSIDL_COMMON_FAVORITES = $1F
Constant CSIDL_INTERNET_CACHE = $20
Constant CSIDL_COOKIES = $21
Constant CSIDL_HISTORY = $22
Constant CSIDL_COMMON_APPDATA = $23 ;All Users\Application Data
Constant CSIDL_WINDOWS = $24 ;GetWindowsDirectory()
Constant CSIDL_SYSTEM = $25 ;GetSystemDirectory()
Constant CSIDL_PROGRAM_FILES = $26 ;C:\Program Files
Constant CSIDL_MYPICTURES = $27 ;C:\Program Files\My Pictures
Constant CSIDL_PROFILE = $28 ;USERPROFILE
Constant CSIDL_SYSTEMX86 = $29 ;x86 system directory on RISC
Constant CSIDL_PROGRAM_FILESX86 = $2A ;x86 C:\Program Files on RISC
Constant CSIDL_PROGRAM_FILES_COMMON = $2B ;C:\Program Files\Common
Constant CSIDL_PROGRAM_FILES_COMMONX86 = $2C ;x86 Program Files\Common on RISC
Constant CSIDL_COMMON_TEMPLATES = $2D ;All Users\Templates
Constant CSIDL_COMMON_DOCUMENTS = $2E ;All Users\Documents
Constant CSIDL_COMMON_ADMINTOOLS = $2F ;All Users\Start Menu\Programs _
;\Administrative Tools
Constant CSIDL_ADMINTOOLS = $30 ;{user}\Start Menu\Programs _
;\Administrative Tools
Constant CSIDL_FLAG_CREATE = $8000& ;combine with CSIDL_ value to force
;create on SHGetSpecialFolderLocation()
Constant CSIDL_FLAG_DONT_VERIFY = $4000 ;combine with CSIDL_ value to force
;create on SHGetSpecialFolderLocation()
Constant CSIDL_FLAG_MASK = $FF00 ;mask for all possible flag values
Constant SHGFP_TYPE_CURRENT = $0 ;current value for user, verify it exists
Constant SHGFP_TYPE_DEFAULT = $1






LinkDll "shell32"
SHGetFolderPath(hWndOwner,nFolder,hToken,dwFlags,pszPath) Alias "SHGetFolderPathA" as integer
EndLinkDll


Function GetSpecialFolderPath(nFolderID)
// Alloc a bank of 1024 bytes for the function to return the path in
Size=1024
ThisBank=newbank(Size)
Ptr=GetBankPtr(thisBank)
Status=SHGetFolderPath(0,nFolderID,0,0,ptr)
if Status=0
// if status is 0 then the function worked
Path$=PeekString(ptr,0) ; peek a null termed string
else
#print "error polling path"
endif
Deletebank ThisBank
EndFunction path$



// Get the location of a Special windows folder


print GetSpecialFolderPath(CSIDL_LOCAL_APPDATA)


print AppDir$
Sync
waitkey