Con estas funciones yo lo hago:
/* ***************************************** */
// Pres del foro de FiveTechSoft el 20/11/2010.
#define CSIDL_PROGRAMS 0x0002 // Start Menu\Programs
#define CSIDL_DESKTOPDIRECTORY 0x0010 // <user name>\Desktop
#define CSIDL_COMMON_STARTMENU 0x0016 // <All Users>\Start Menu
#define CSIDL_COMMON_DESKTOPDIRECTORY 0x0019 // <All Users>\Desktop
#define CSIDL_PROFILE 0x0028 // C:\Documents and Settings\<user name>
#define CSIDL_PROGRAM_FILES 0x0026 // C:\Program Files
#define CSIDL_FAVORITES 0x0006 // "C:\Documents and Settings\User\Favorites"
#define CSIDL_COMMON_FAVORITES 0x001F // "C:\Documents and Settings\All Users\Favorites"
#define CSIDL_MYDOCUMENTS 0x000C // Virtual "C:\Documents and Settings\username\My Documents"
#define CSIDL_PERSONAL 0x0005 // "C:\Documents and Settings\user\My Documents"
/* ***************************************** */
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetMisDocumentos()
// C:\Documents and Settings\Usuario\Escritorio
Local cMisDocumentos := Nil
cMisDocumentos := GETSPECIALFOLDER( CSIDL_PERSONAL )
Return cMisDocumentos
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetAllUsersProfile()
// A Windows Vista o superior -->> C:\ProgramData
// A Windows XP o inferior -->> C:\Documents and Settings\All Users
Local cAllUsersProfile := Nil
cAllUsersProfile := GetEnv( "ALLUSERSPROFILE" )
Return cAllUsersProfile
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetProgramFiles()
// C:\Program Files
Local cProgramFiles := Nil
cProgramFiles := GETSPECIALFOLDER( CSIDL_PROGRAM_FILES )
Return cProgramFiles
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetUserFavoritos()
// C:\Documents and Settings\User\Favorites
Local cFavoritos := Nil
cFavoritos := GETSPECIALFOLDER( CSIDL_FAVORITES )
Return cFavoritos
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetAllUsersFavoritos()
// C:\Documents and Settings\All Users\Favorites
Local cFavoritos := Nil
cFavoritos := GETSPECIALFOLDER( CSIDL_COMMON_FAVORITES )
Return cFavoritos
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetUserEscritorio()
// C:\Documents and Settings\Usuario\Escritorio
Local cEscritorio := Nil
cEscritorio := GETSPECIALFOLDER( CSIDL_DESKTOPDIRECTORY )
Return cEscritorio
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetEscritorio()
// C:\Documents and Settings\TodosUsuarios\Escritorio
Local cEscritorio := Nil
cEscritorio := GETSPECIALFOLDER( CSIDL_COMMON_DESKTOPDIRECTORY )
Return cEscritorio
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetUserMenuStart()
// C:\Documents and Settings\Usuario\Menú Inicio\Programas
Local cMenuStart := Nil
cMenuStart := GETSPECIALFOLDER( CSIDL_PROGRAMS )
Return cMenuStart
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetMenuStart()
// C:\Documents and Settings\TodosUsuarios\Menú Inicio\Programas
Local cMenuStart := Nil
cMenuStart := GETSPECIALFOLDER( CSIDL_COMMON_STARTMENU )
Return cMenuStart
/* ***************************************** */
/* ***************************************** */
FUNCTION cGetFolderUser()
// C:\Documents and Settings\Usuario
Local cMenuStart := Nil
cMenuStart := GETSPECIALFOLDER( CSIDL_PROFILE )
Return cMenuStart
/* ***************************************** */
*---------------------------------------------------------------*
Function GETSPECIALFOLDER(nCSIDL) // Contributed By Ryszard Rylko
*---------------------------------------------------------------*
RETURN C_getspecialfolder(nCSIDL)
*---------------------------------------------------------------*
#pragma BEGINDUMP
#include <windows.h>
#include <shlobj.h>
#include "hbapi.h"
#include "hbapiitm.h"
HB_FUNC( C_GETSPECIALFOLDER ) // Contributed By Ryszard RyRko
{
char *lpBuffer = (char*) hb_xgrab( MAX_PATH+1);
LPITEMIDLIST pidlBrowse; // PIDL selected by user
SHGetSpecialFolderLocation(GetActiveWindow(), hb_parni(1), &pidlBrowse)
;
SHGetPathFromIDList(pidlBrowse, lpBuffer);
hb_retc(lpBuffer);
hb_xfree( lpBuffer);
}
#pragma ENDDUMP
*---------------------------------------------------------------*
*---------------------------------------------------
FUNCTION pLnk( cFile, cNameLnk, cWorkingDir, cIcon, cParameters )
*---------------------------------------------------
LOCAL oShell, oLnk
DEFAULT cFile := ''
DEFAULT cNameLnk := ''
DEFAULT cWorkingDir := ''
DEFAULT cIcon := ''
IF !File( cFile )
RETU .F.
ENDIF
IF Empty( cNameLnk )
cNameLnk := cFilePath( cFile ) + cFileNoExt( cFile ) + '.lnk'
ENDIF
IF Empty( cWorkingDir )
cWorkingDir := cFilePath( cFile )
ENDIF
TRY
oShell := CreateObject( "Wscript.Shell" )
CATCH
MsgAlert( 'Error Create object WScript.Shell', 'Error' )
RETU .F.
END
oLnk := oShell:CreateShortcut( cNameLnk )
oLnk:TargetPath := cFile
If !Empty(cParameters)
oLnk:Arguments := cParameters
// Else
// oLnk:TargetPath := cFile + '"' + cParameters
EndIf
oLnk:WindowStyle := 3
IF !Empty( cIcon )
oLnk:IconLocation := cIcon
ENDIF
IF !Empty( cWorkingDir )
oLnk:WorkingDirectory := cWorkingDir
ENDIF
* oLnk:Description := 'Hola calc...'
* oLnk:Hotkey := "CTRL+ALT+SHIFT+X"
oLnk:Save()
RETU .T.
/* ***************************************** */
pLnk( cPathEXE( .T. ) + Fileexe( AMPAARRA ), cDummyPathFile, Nil, Nil, "/F:" + cDummyParam1 )
// cFile, cNameLnk, cWorkingDir, cIcon, cParameters )