OVH Cloud OVH Cloud

création de raccourcis (bureau ou menu démarer etc...)

1 réponse
Avatar
Philippe M
Dans le but de créer un installeur pour faire fonctionner une application,
j'aimerai savoir comment vous arrivez a créer un raccourcis d'un ".exe" via
lignes de code C# pour l'integrer sur le bureau et dans le menu démarer ?

merci d'avance pour vos suggestions.

1 réponse

Avatar
Nicolas Guinet
Ca marche avec le "Windows Script Host Object Model"

// Ajouter au projet :
// La référence COM "Windows Script Host Object Model"

using IWshRuntimeLibrary;

.....

string linkPath =
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
linkPath += "" + Application.ProductName + ".lnk";
string exePath = Application.ExecutablePath;

try
{
// On définit les paramètres du raccourci :
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut( linkPath );
link.TargetPath = exePath;
// on pourrait aussi ajouter ici l'icone...etc
link.Save();

//ou avec link.Update(
}
catch
{
MessageBox.Show("Erreur de création du raccourci " + linkPath,
"Shell Link Error",MessageBoxButtons.OK,
MessageBoxIcon.Error);
}


Faudrait voir si on peut avec Process.Start(...)

Détails ici
http://www.codeproject.com/dotnet/shelllink.asp

Nicolas GUINET

"Philippe M" a écrit dans le message
de news:
Dans le but de créer un installeur pour faire fonctionner une
application,
j'aimerai savoir comment vous arrivez a créer un raccourcis d'un ".exe"
via
lignes de code C# pour l'integrer sur le bureau et dans le menu démarer ?

merci d'avance pour vos suggestions.