CRÉATION ET MODIFICATION DE RACCOURCIS WINDOWS (.LNK) AVEC INTERFACE ISHELLLINK

yann_lo_san Messages postés 1137 Date d'inscription lundi 17 novembre 2003 Statut Membre Dernière intervention 23 janvier 2016 - 25 févr. 2013 à 20:23
yann_lo_san Messages postés 1137 Date d'inscription lundi 17 novembre 2003 Statut Membre Dernière intervention 23 janvier 2016 - 25 févr. 2013 à 20:23
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/54988-creation-et-modification-de-raccourcis-windows-lnk-avec-interface-ishelllink

yann_lo_san Messages postés 1137 Date d'inscription lundi 17 novembre 2003 Statut Membre Dernière intervention 23 janvier 2016 26
25 févr. 2013 à 20:23
Salut,

Pas mal, beaucoup de travail en p-invoke, mais...
Tu penses bien que Microsoft avait prévu cela en .net natif.

1 : Ajouter la référence COM suivante au projet : Windows Script Host object Model

2 : ajouter le using suivant : using IWshRuntimeLibrary;

3 : utiliser ce code :

private void CreateShortCut(string sPathLNK)
{
WshShellClass shell = new WshShellClass();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(sPathLNK);
shortcut.TargetPath = Application.ExecutablePath; // ou autre
//shortcut.IconLocation = "location de l'icone";
// Description
shortcut.Description = "La description ici";
// save / create
shortcut.Save();
}

c'est tout !

bye...
Rejoignez-nous