Sets the per-process mode that the SearchPath function uses when locating files.
Syntax
Parameters
- Flags [in]
The search mode to use.
Return Value
If the operation completes successfully, the SetSearchPathMode function returns a nonzero value.
If the operation fails, the SetSearchPathMode function returns zero. To get extended error information, call the GetLastError function.
If the SetSearchPathMode function fails because a parameter value is not valid, the value returned by the GetLastError function will be ERROR_INVALID_PARAMETER.
If the SetSearchPathMode function fails because the combination of current state and parameter value is not valid, the value returned by the GetLastError function will be ERROR_ACCESS_DENIED. For more information, see the Remarks section.
Remarks
If the SetSearchPathMode function has not been successfully called for the current process, the search mode used by the SearchPath function is obtained from the system registry. For more information, see SearchPath.
After the SetSearchPathMode function has been successfully called for the current process, the setting in the system registry is ignored in favor of the mode most recently set successfully.
If the SetSearchPathMode function has been successfully called for the current process with Flags set to (BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE & BASE_SEARCH_PATH_PERMANENT)
, safe mode is set permanently for the calling process. Any subsequent calls to the SetSearchPathMode function from within that process that attempt to change the search mode will fail with ERROR_ACCESS_DENIED from the GetLastError function.
Note Because setting safe search mode permanently cannot be disabled for the life of the process for which is was set, it should be used with careful consideration. This is particularly true for DLL development, where the user of the DLL will be affected by this process-wide setting.
It is not possible to permanently disable safe search mode.
This function does not modify the system registry.
Requirements
Minimum supported client | Windows 7 |
---|---|
Minimum supported server | Windows Server 2008 R2 |
Redistributable | KB959426 on Windows XP with Service Pack 2 (SP2) and later and Windows Server 2003 with Service Pack 1 (SP1) and later |
Header | Winbase.h (include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
See Also
Send comments about this topic to Microsoft
Build date: 8/19/2010
The ShellExecute function, however, does not appear to respect the safe search mode setting; it always searches the current directory before the system directories. (Tested on XP)
- 9/6/2010
- jrx