Possible en double:
How do you create an application shortcut (.lnk file) in C# or .Netraccourci application
Salut,
Toute idée sur la façon de créer un raccourci pour un fichier .exe en C#?
Merci
Possible en double:
How do you create an application shortcut (.lnk file) in C# or .Netraccourci application
Salut,
Toute idée sur la façon de créer un raccourci pour un fichier .exe en C#?
Merci
Je trouve cette réponse dans Google, à l'adresse: http://www.geekpedia.com/tutorial125_Create-shortcuts-with-a-.NET-application.html
Just:
WshShell = new WshShellClass();
// Create the shortcut
IWshRuntimeLibrary.IWshShortcut MyShortcut;
// Choose the path for the shortcut
MyShortcut = IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk");
// Where the shortcut should point to
MyShortcut.TargetPath = Application.ExecutablePath;
// Description for the shortcut
MyShortcut.Description = "Launch My Application";
// Location for the shortcut's icon
MyShortcut.IconLocation = Application.StartupPath + @"\app.ico";
// Create the shortcut at the given path
MyShortcut.Save();
Rappelez-vous simplement d'ajouter la référence Windows Script Object Model Host
Ceci est la même réponse donnée dans la [question en double] (http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c-or- net). –
@Andy Ce n'est * pas * la même réponse donnée dans le fil dupliqué. L'autre thread utilise l'API appropriée - L'objet COM ShellLink, que quelqu'un a enveloppé dans un wrapper géré. –
@Ian: Peut-être que je devrais avoir lié droit à [la réponse en double] (http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c -ou-net/234243 # 234243). La seule différence ici est que le code a été collé à partir du site lié. –
Voici mon Delphi code:
function CreateShellLink(const szFilename: string; const szDescription: string): IShellLinkA;
var
sl: IShellLinkA;
begin
sl := CreateComObject(CLSID_ShellLink) as IShellLinkA;
OleCheck(sl.SetPath(szFilename));
OleCheck(sl.SetDescription(szDescription));
Result := sl;
end;
Vous aurez à comprendre en utilisant Win32 API de .NET.
Bien que cela soit pertinent, cela n'est guère utile pour l'OP ... –
Eh bien, c'est un peu utile, c'est la bonne façon de le faire. –
Propre selon quoi? –
Avez-vous essayé Google? http://www.google.com/search?q=c%23+create+shortcut, des dizaines de résultats. –