create a desktop shortcut directly from the program
create a desktop shortcut directly from the program
I have a program that will set up 4 identical programs (exes) in 4 folders on a net work. Is there a way to set up a shortcut on the network directly from the program to the copies of the exes in their separate folders???
Thank you
Harvey
Harvey
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: create a desktop shortcut directly from the program
Harvey,
Can you just do that with the install program?
Regards,
James
Can you just do that with the install program?
Regards,
James
Re: create a desktop shortcut directly from the program
James took your advice and programmed the install to do what I wank. Thanks.
Thank you
Harvey
Harvey
Re: create a desktop shortcut directly from the program
Try:
cUser:= GetEnv( "USERPROFILE" )
I
f Left(cUser,8)="C:\Users" //Language of SO
cEscritorio:=cUser+"\desktop\file.lnk"
Else
cEscritorio:=cUser+"\escritorio\file.lnk"
Endif
COPY FILE C:\FILE.LNK TO (cEscritorio)
cUser:= GetEnv( "USERPROFILE" )
I
f Left(cUser,8)="C:\Users" //Language of SO
cEscritorio:=cUser+"\desktop\file.lnk"
Else
cEscritorio:=cUser+"\escritorio\file.lnk"
Endif
COPY FILE C:\FILE.LNK TO (cEscritorio)
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Re: create a desktop shortcut directly from the program
You can try::
File: "shortcut.c"
Prg file : XXX.prg
I hope that you have helped.
Pere
File: "shortcut.c"
Code: Select all
#pragma BEGINDUMP
#define _WIN32_IE 0x0500
#define HB_OS_WIN_32_USED
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <commctrl.h>
#include <shlobj.h>
#include <hbapi.h>
#include "hbstack.h"
#include "hbapiitm.h"
#include "winreg.h"
#include "tchar.h"
#define HB_OS_WIN_32_USED
#define _WIN32_WINNT 0x0400
// #define OEMRESOURCE
#include <windows.h>
#include <shlobj.h>
#include "hbapi.h"
#include "hbapiitm.h"
#define ID_NOTIFYICON 1
#define WM_NOTIFYICON WM_USER+1000
#ifndef BIF_USENEWUI
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040 // Use the new dialog layout with the ability to resize
#endif
#define BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
#endif
// link executor *******************
void ChangePIF(LPCSTR cPIF);
HRESULT WINAPI CreateLink(LPSTR lpszLink, LPSTR lpszPathObj,LPSTR szWorkPath,LPSTR lpszIco, int nIco,LPSTR szDescription);
HB_FUNC( CREATEFILELINK )
{
hb_retnl( (LONG) CreateLink( hb_parc(1), hb_parc(2), hb_parc(3),hb_parc(4), hb_parni(5) ,hb_parc(6) ) );
}
void ChangePIF(LPCSTR cPIF)
{
UCHAR buffer[1024];
HFILE h;
long filesize;
strcpy(buffer, cPIF);
strcat(buffer, ".pif");
if ((h=_lopen(buffer, 2))>0)
{
filesize=_hread(h, &buffer, 1024);
buffer[0x63]=0x10; // Cerrar al salir
buffer[0x1ad]=0x0a; // Pantalla completa
buffer[0x2d4]=0x01;
buffer[0x2c5]=0x22; // No Permitir protector de pantalla
buffer[0x1ae]=0x11; // Quitar ALT+ENTRAR
buffer[0x2e0]=0x01;
_llseek(h, 0, 0);
_hwrite(h, buffer, filesize);
_lclose(h);
}
}
// Canviem el pif
HB_FUNC( CHANGE_PIF )
{
ChangePIF( hb_parc(1) ) ;
}
HRESULT WINAPI CreateLink(LPSTR lpszLink, LPSTR lpszPathObj,LPSTR szWorkPath,LPSTR lpszIco, int nIco,LPSTR szDescription)
{
long hres;
IShellLink * psl;
hres = CoInitialize(NULL);
if (SUCCEEDED(hres))
{
hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, ( LPVOID ) &psl);
if (SUCCEEDED(hres))
{
IPersistFile * ppf;
psl->lpVtbl->SetPath(psl, lpszPathObj);
psl->lpVtbl->SetIconLocation(psl, lpszIco, nIco);
psl->lpVtbl->SetWorkingDirectory(psl, szWorkPath);
psl->lpVtbl->SetDescription(psl,szDescription);
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,( LPVOID ) &ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
char appPath[MAX_PATH];
strcpy(appPath, lpszLink);
strcat(appPath, ".lnk");
MultiByteToWideChar(CP_ACP, 0, appPath, -1, wsz, MAX_PATH);
hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
ppf->lpVtbl->Release(ppf);
// modificar el PIF para los programas MS-DOS
ChangePIF(lpszLink);
}
psl->lpVtbl->Release(psl);
}
CoUninitialize();
}
return hres;
}
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);
}
// eop link executor *******************
#pragma ENDDUMP-------------------------------------------------------
Prg file : XXX.prg
Code: Select all
*-------------------------------------------------------
Procedure CreateLink( lDesk, lMenu )
*--------------------------------------------------------*
local cDesktop := GetSpecialFolder( CSIDL_DESKTOPDIRECTORY )
local cMenuPrgs := GetSpecialFolder( CSIDL_PROGRAMS )
local cLinkName := "proves"
local cExeName := ExeName()
Local cFilePath
local cIco := ""
If CurDrive() = "@"
cFilePath:= NetRmtName( CurDrive()+":" )+"\"+CURDIR()
Else
cFilePath:= CurDrive()+":\"+CURDIR()
EndIf
cIco := cExeName
if lDesk && desktop
if CreateFileLink( cDesktop + "\" + cLinkName, cExeName,cFilePath,cIco ) # 0
Duda( "Create Link Error!", "Acceptar")
endif
endif
if lMenu && menu start
if CreateFileLink( cMenuPrgs + "\" + cLinkName, cExeName,cFilePath,cIco ) # 0
Duda( "Create Link Error!", "Acceptar")
endif
endif
Return
Pere
Re: create a desktop shortcut directly from the program
Thank you all for the help. Working great.
Thank you
Harvey
Harvey
- RAMESHBABU
- Posts: 591
- Joined: Fri Oct 21, 2005 5:54 am
- Location: Secunderabad (T.S), India
Re: create a desktop shortcut directly from the program
Hi,
You can even try this simple class. Works great.
- Ramesh Babu
You can even try this simple class. Works great.
- Ramesh Babu
Code: Select all
#include "FiveWin.ch"
*****************************************************************************
*** Class : ZLnk() ***
*** Descripction : To Create Shortcut Links ***
*** Author : Carles Aubia ***
*** Created on : 04.07.2006 ***
*****************************************************************************
FUNCTION Main()
LOCAL o
o := ZLnk():New( 'C:\Windows\system32\notepad.exe' )
o:cFolder := 'Programs' //o:cFolder := 'DeskTop' or 'StartMenu' or 'StartUp' or 'Programs'
o:Run()
/*
o := ZLnk():New( 'C:\xHarbour\bin\Harbour.exe' )
o:cNameLnk := 'Harbour.lnk'
o:cFolder := 'DeskTop'
o:cDescription := 'xHarbour'
o:cWorkingDirectory := o:cFolder
o:cIconLocation :='C:\xHarbour\bin'
o:cHotKey := "CTRL+SHIFT+H"
o:Run()
*/
RETURN nil
*****************************************************************************
*** ZLnk Class ***
*****************************************************************************
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 ***
*****************************************************************************
METHOD New( cFile ) CLASS ZLnk
::cFile := cFile
RETURN Self
*****************************************************************************
*** METHOD Run() CLASS ZLnk ***
*****************************************************************************
METHOD Run() CLASS ZLnk
LOCAL oShell, oSF, o
LOCAL cTarget
IF !File( ::cFile )
RETURN .F.
ENDIF
IF Empty( ::cNameLnk )
::cNameLnk := cFileNoExt( ::cFile ) + '.lnk'
ENDIF
oShell := TOleAuto():New( "WScript.Shell" )
IF oShell:hObj == 0
RETURN .F.
ENDIF
oSF := oShell:Get( 'SpecialFolders' )
cTarget := oSF:Item( ::cFolder )
IF Empty( cTarget )
RETURN .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()
RETURN .T.
**************************
*** EOF() SHORTCUT.PRG ***
**************************