2010-06-12 4 views

Répondre

3

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

+1

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). –

+0

@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é. –

+0

@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é. –

-2

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.

+1

Bien que cela soit pertinent, cela n'est guère utile pour l'OP ... –

+0

Eh bien, c'est un peu utile, c'est la bonne façon de le faire. –

+0

Propre selon quoi? –