Shortcut (*.lnk) from FWH
Posted: Thu Jun 29, 2006 11:22 am
Hi,
Do you know as creating a shortcut (*.lnk) from FWH?
Thanks.
Regards.
Do you know as creating a shortcut (*.lnk) from FWH?
Thanks.
Regards.
www.FiveTechSoft.com
https://fivetechsoft.com/forums/
Code: Select all
#include 'fivewin.ch'
FUNCTION Main()
CreateLink( 'DeskTop', "My Program", "c:\temp\Test.exe", "main.exe,0", "c:\temp" )
RETU NIL
FUNCTION CreateLink( cDest, sName, sPath, sIcon, sWorkingDirectory )
LOCAL oShell := TOleAuto():New( "WScript.Shell" )
LOCAL oSF := oShell:Get( 'SpecialFolders' )
LOCAL o
LOCAL cTarget
* cTarget := oSF:Get( cDest )
* o := oShell:CreateShortCut( cTarget )
o := oShell:CreateShortCut( 'C:\temp\Test.lnk' )
o:TargetPath := sPath
o:WorkingDirectory := sWorkingDirectory
o:Description := sName
o:IconLocation := sIcon
o:Save()
oShell:End()
RETU NIL
Code: Select all
#include "FiveWin.ch"
*
* Clase : ZLnk()
* Descripcion : Crear accesos directos
* Autor : Carles Aubia
* Fecha : 04.07.2006
* Observaciones: El acceso Ole se hace con la clase TOleAuto
*
/* Test
*--------------
FUNCTION Main()
*--------------
LOCAL o
o := ZLnk():New( 'c:\winnt\system32\calc.exe' )
o:Run()
o := ZLnk():New( 'c:\winnt\system32\calc.exe' )
o:cNameLnk := 'Calculadora.lnk'
o:cDescription := 'Calculadora del sistema'
o:Run()
RETU NIL
*/
// cFolder: DeskTop, StartMenu, StartUp, Programs
// cHotKey: "CTRL+SHIFT+C"
*---------
CLASS ZLnk
*---------
DATA cFolder AS CHARACTER INIT 'Desktop'
DATA cWindowStyle AS NUMERIC INIT 1
DATA cFile AS CHARACTER INIT ''
DATA cWorkingDirectory AS CHARACTER INIT ''
DATA cDescription AS CHARACTER INIT ''
DATA cIconLocation AS CHARACTER INIT ''
DATA cNameLnk AS CHARACTER INIT ''
DATA cHotKey AS CHARACTER INIT ''
METHOD New( cFile ) CONSTRUCTOR
METHOD Run()
ENDCLASS
*-----------------------------
METHOD New( cFile ) CLASS ZLnk
*-----------------------------
::cFile := cFile
RETU Self
*----------------------
METHOD Run() CLASS ZLnk
*----------------------
LOCAL oShell, oSF, o
LOCAL cTarget
IF !File( ::cFile )
RETU .F.
ENDIF
IF Empty( ::cNameLnk )
::cNameLnk := cFileNoExt( ::cFile ) + '.lnk'
ENDIF
oShell := TOleAuto():New( "WScript.Shell" )
IF oShell:hObj == 0
RETU .F.
ENDIF
oSF := oShell:Get( 'SpecialFolders' )
cTarget := oSF:Item( ::cFolder )
IF Empty( cTarget )
RETU .F.
ENDIF
o := oShell:CreateShortCut( cTarget + '\' + ::cNameLnk )
o:WindowStyle := ::cWindowStyle
o:TargetPath := ::cFile
o:WorkingDirectory := ::cWorkingDirectory
o:Description := ::cDescription
o:IconLocation := ::cIconLocation
o:HotKey := ::cHotKey
o:Save()
RETU .T.
EMGError description: Error WScript.Shell:CREATESHORTCUT/16389 E_FAIL: _ICONLOCATION
Args:
[ 1] = C
Stack Calls
===========
Called from: win32ole.prg => TOLEAUTO:_ICONLOCATION(0)
Called from: CREATELINK.prg => ZLNK:RUN(101)
Called from: CREATELINK.prg => MAIN(21)
Code: Select all
#include "FiveWin.ch"
*
* Clase : ZLnk()
* Descripcion : Crear accesos directos
* Autor : Carles Aubia
* Fecha : 04.07.2006
* Modificacion : 05.07.2006
* Observaciones: El acceso Ole se hace con la clase TOleAuto
*
/* Test
*--------------
FUNCTION Main()
*--------------
LOCAL o
o := ZLnk():New( 'c:\winnt\system32\calc.exe' )
o:Run()
o := ZLnk():New( 'c:\winnt\system32\calc.exe' )
o:cNameLnk := 'Calculadora.lnk'
o:cDescription := 'Calculadora del sistema'
o:cIconLocation := 'c:\temp\alert.ico'
Msginfo( o:IsLnk() )
o:Run()
RETU NIL
*/
// cFolder: DeskTop, StartMenu, StartUp, Programs
// cHotKey: "CTRL+SHIFT+C"
*---------
CLASS ZLnk
*---------
DATA cFolder AS CHARACTER INIT 'Desktop'
DATA nWindowStyle AS NUMERIC INIT 1
DATA cFile AS CHARACTER INIT ''
DATA cWorkingDirectory AS CHARACTER INIT ''
DATA cDescription AS CHARACTER INIT ''
DATA cIconLocation AS CHARACTER INIT ''
DATA cNameLnk AS CHARACTER INIT ''
DATA cHotKey AS CHARACTER INIT ''
METHOD New( cFile ) CONSTRUCTOR
METHOD IsLnk()
METHOD Run()
ENDCLASS
*-----------------------------
METHOD New( cFile ) CLASS ZLnk
*-----------------------------
::cFile := cFile
RETU Self
*----------------------
METHOD Run() CLASS ZLnk
*----------------------
LOCAL oShell, oSF, o
LOCAL cTarget
IF !File( ::cFile )
RETU .F.
ENDIF
IF Empty( ::cNameLnk )
::cNameLnk := cFileNoExt( ::cFile ) + '.lnk'
ENDIF
oShell := TOleAuto():New( "WScript.Shell" )
IF oShell:hObj == 0
RETU .F.
ENDIF
oSF := oShell:Get( 'SpecialFolders' )
cTarget := oSF:Item( ::cFolder )
IF Empty( cTarget )
RETU .F.
ENDIF
o := oShell:CreateShortCut( cTarget + '\' + ::cNameLnk )
o:WindowStyle := ::nWindowStyle
o:TargetPath := ::cFile
o:WorkingDirectory := IF( !Empty( ::cWorkingDirectory ), ::cWorkingDirectory, NIL )
o:Description := IF( !Empty( ::cDescription ), ::cDescription , NIL )
o:IconLocation := IF( !Empty( ::cIconLocation ), ::cIconLocation , NIL )
o:HotKey := IF( !Empty( ::cHotKey ), ::cHotKey , NIL )
o:Save()
RETU .T.
*------------------------
METHOD IsLnk() CLASS ZLnk
*------------------------
LOCAL oShell, oSF, o
LOCAL cTarget
LOCAL cFileLnk
IF !File( ::cFile )
RETU .F.
ENDIF
IF Empty( ::cNameLnk )
::cNameLnk := cFileNoExt( ::cFile ) + '.lnk'
ENDIF
oShell := TOleAuto():New( "WScript.Shell" )
IF oShell:hObj == 0
RETU .F.
ENDIF
oSF := oShell:Get( 'SpecialFolders' )
cTarget := oSF:Item( ::cFolder )
IF Empty( cTarget )
RETU .F.
ENDIF
cFileLnk := cTarget + '\' + ::cNameLnk
RETU File( cFileLnk )