5 out of 12 rated this helpful - Rate this topic

SHGetSpecialFolderPath function

[SHGetSpecialFolderPath is not supported. Instead, use ShGetFolderPath.]

Applies to: desktop apps only

Retrieves the path of a special folder, identified by its CSIDL.

Syntax

BOOL SHGetSpecialFolderPath(
  HWND hwndOwner,
  __out  LPTSTR lpszPath,
  __in   int csidl,
  __in   BOOL fCreate
);

Parameters

hwndOwner

Type: HWND

Reserved.

lpszPath [out]

Type: LPTSTR

A pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.

csidl [in]

Type: int

A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.

fCreate [in]

Type: BOOL

Indicates whether the folder should be created if it does not already exist. If this value is nonzero, the folder is created. If this value is zero, the folder is not created.

Return value

Type: BOOL

TRUE if successful; otherwise, FALSE.

Remarks

The Microsoft Internet Explorer 4.0 Desktop Update must be installed for this function to be available.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

End of client support

Windows 2000 Professional

End of server support

Windows 2000 Server

Header

Shlobj.h

Library

Shell32.lib

DLL

Shell32.dll (version 4.71 or later)

Unicode and ANSI names

SHGetSpecialFolderPathW (Unicode) and SHGetSpecialFolderPathA (ANSI)

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
info incorrect new info shgetspecialfolderpath
updat windows exploer 9 .exe save hide
CSIDL Virtual Folder works
Although the documentation here claims passing a CSIDL of a virtual folder will fail, I have tested with CSIDL_PERSONAL (which is said to be the ID of the Virtual folder "My Documents" as of shlwapi.dll 6.0) and it in fact succeeds, returning the appropriate path to the user's "My Documents".$0 $0$0 $0 $0So, it seems that is only those virtual folders that do not have corresponding file system directories, such as CSIDL_CONTROLS (Control Panel) and CSIDL_DRIVES (My Computer), that will cause this to fail.$0 $0$0 $0 $0This can be tested with the following Python script:$0 $0$0 $0 $0 $0$0 $0$0 $0$0 $0 $0
# Copyright (C) 2011 Samuel Bronson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including 
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Uses PyWin32; see <http://sourceforge.net/projects/pywin32/files/pywin32/>

import pywintypes
from win32com.shell import shell, shellcon

csidl_names = [s for s in dir(shellcon)
               if s.startswith('CSIDL_') and not s.startswith('CSIDL_FLAG_')]

def GetSpecialFolderPath(csidl):
    return shell.SHGetSpecialFolderPath(0, csidl, 0)

def GetSpecialFolderLocation(csidl):
    return shell.SHGetSpecialFolderLocation(0, csidl)

def test(fun):
    fails = set()
    for s in csidl_names:
        try:
            csidl = shellcon.__dict__[s]
            fun(csidl)
        except pywintypes.com_error, e:
            fails.add(s)
    return fails

if __name__ == '__main__':
    print "CSIDLs failing only for SHGetSpecialFolderPath:"
    print test(GetSpecialFolderPath) - test(GetSpecialFolderLocation)
$0
$0On XP SP3 (x86), with pywin32 build 216 on Python 2.6, I (Samuel Bronson) get the following output from this script:$0 $0$0 $0 $0 $0$0 $0 $0
CSIDLs failing only for SHGetSpecialFolderPath:
set(['CSIDL_NETWORK', 'CSIDL_COMPUTERSNEARME', 'CSIDL_CONTROLS', 'CSIDL_BITBUCKET', 'CSIDL_CONNECTIONS', 'CSIDL_INTERNET', 'CSIDL_PRINTERS', 'CSIDL_DRIVES'])
$0
$0$0 $0