Les Snippets

Connexion

Créer le raccourci de l'application sur le bureau

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 04/03/2007 21:26:40 et initié par mortalino [Liste]
Date de mise à jour : 26/04/2008 17:40:25
Vue : 12332
Catégorie(s) : Fichier / Disque, Trucs & Astuces, Divers
Langages dispo pour ce code :
- VB6
- Javascript
- C# 1.x, C# 2.x
- Windev
- Delphi 5
- VB 2005
- VBA



Langage : VB6
Date ajout : 04/03/2007
Posté par mortalino [Liste]
Option Explicit
'Ajoutez  la référence Windows Script Host Object Model (wshom.ocx) à votre  projet.
Private Sub CreateShortCutOnDeskTop()
    Dim Wsh             As New WshShell
    Dim DesktopPath As String
    Dim FileName       As String
    Dim Shortcut         As Variant
DesktopPath = Wsh.SpecialFolders("Desktop")
FileName = DesktopPath & "\MonAppli.lnk"
If FileExist(FileName) = False Then
    Set Shortcut = Wsh.CreateShortcut(FileName)
    With Shortcut
        .TargetPath = App.Path & "\" & App.EXEName
        .Description = "Mon  Programme"
        .WindowStyle = 4
        .Save
    End With
End If
End Sub
Private Function FileExist(ByRef inFile As String) As Boolean
    'Fonction provenant  de EDais (edais.mvps.org)
    On Error Resume Next
    Let FileExist = CBool(FileLen(inFile) + 1)
End Function

Langage : Javascript
Date ajout : 06/03/2007
Posté par bultez [Liste]

        var Shl = new ActiveXObject("WScript.Shell");
        var Dsk = Shl.SpecialFolders("Desktop");
        var lnk = Shl.CreateShortcut(Dsk + "\\nom du raccourci.lnk" );
        lnk.TargetPath = "adresse de l'exécutable";
        // lnk.IconLocation = "adresse du fichier des icônes,indice icône à utiliser";
        lnk.Save();


Remarque :
tel quel, ne fonctionne, hélas,
qu'avec Windows et Internet Explorer.
Langage : C# 1.x , C# 2.x
Date ajout : 14/03/2007
Posté par Bidou [Liste]
DateMAJ : 14/03/2007
private static string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
private static string fileName = "Calc.lnk";

private static void Main(string[] args) 
{
   WshShell shell = new WshShell();
   IWshShortcut link = (IWshShortcut)shell.CreateShortcut(Path.Combine(desktop, fileName));
   link.TargetPath = @"C:\WINDOWS\system32\calc.exe";
   link.Save();
}



Remarque :
using System;
using System.IO;
using IWshRuntimeLibrary;
Langage : Windev
Date ajout : 14/03/2007
Posté par fabienlaps [Liste]
// Crée le raccourci "Test" du programme "C:\Test\Test.exe" // sur le bureau, avec Ctrl-Alt-A comme raccourci clavier CréeRaccourci(RaccourciBureau, "Test", "C:\Test\Test.exe", "", sfaNormal, "A")
Langage : Delphi 5
Date ajout : 30/03/2007
Posté par japee [Liste]
DateMAJ : 30/03/2007
uses ComObj, ActiveX, ShlObj;
function CreateShortCutOnDeskTop(const FileName, scLabel: string): Boolean;
var
  AnObj    : IUnknown;
  ShLink   : IShellLink;
  PFile    : IPersistFile;
  LinkName : WideString;
  SFolder  : pItemIDList;
  DeskTop  : array[0..MAX_PATH] of Char;
  Target   : string;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, SFolder);
  SHGetPathFromIDList(SFolder, DeskTop);
  Target := Concat(StrPas(DeskTop), '\');
  AnObj  := CreateComObject(CLSID_ShellLink);
  ShLink := AnObj as IShellLink;
  PFile  := AnObj as IPersistFile;
  ShLink.SetPath(PChar(FileName));
  ShLink.SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
  LinkName := ChangeFileExt(scLabel, '.lnk');
  Result := (PFile.Save(PWChar(Target + LinkName), False) = S_OK);
end;
Remarque :
Attention à bien déclarer ComObj, ActiveX et ShlObj.

La fonction retourne True si le raccourci a pu être créé.

Exemple d'utilisation :

procedure TForm1.btnCreateShortCutClick(Sender: TObject);
var AppliToLink, ShorCutLabel: string;
begin
  AppliToLink := 'C:\Program Files\Mon Appli.exe';
  ShorCutLabel := 'Raccourci ver Mon Appli';
  if CreateShortCutOnDeskTop(AppliToLink, ShorCutLabel) then
    ShowMessage('Raccourci créé avec succès')
  else
    ShowMessage('Impossible de créer le raccourci');
end;
Langage : VB 2005
Date ajout : 17/04/2007
Posté par dp_favresa [Liste]
 '   Création du raccourci sur le bureau
'   Demande l'ajout de la référence wshom.ocx depuis Winnt\System32
Dim Bureau As IWshRuntimeLibrary.WshShell
Dim Raccourci As IWshRuntimeLibrary.WshShortcut
Dim VarTrav As String
Bureau = New IWshRuntimeLibrary.WshShell
'   Chemin et nom du raccourci
VarTrav = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Saisie listes VB.lnk"
Raccourci = Bureau.CreateShortcut(VarTrav)
'   Cible
Raccourci.TargetPath = "D:\SaisieListes\SaisieListes.exe"
'   Icône
Raccourci.IconLocation = "D:\SaisieListes\INI\BarreAcierS500.ico"
'    Enregistrement
Raccourci.Save()

Langage : VBA
Date ajout : 21/04/2008
Posté par Le Pivert [Liste]
DateMAJ : 26/04/2008
'utilise Windows Scripting Host Model
'autres propriétés accessibles:
'    oShellLink.Hotkey (ex : = "CTRL+SHIFT+F")
'    oShellLink.IconLocation (ex : = "notepad.exe, 0")
'    oShellLink.Description (ex = "Raccourci classeur Excel") '    oShellLink.WorkingDirectory (ex = strDesktop) Sub CreerRaccourci(CheminCible)     Set WSHShell = CreateObject("WScript.Shell")     strDesktop = WSHShell.SpecialFolders("Desktop")     Set oShellLink = WSHShell.CreateShortcut(strDesktop & "\ Raccourci classeur Excel.lnk")     oShellLink.TargetPath = CheminCible     oShellLink.Description = "Calcul Mental"     oShellLink.WindowStyle = 1     oShellLink.Save End Sub   'Activer Sub TestRaccourci()     'On cherche le fichier     CreerRaccourci (ActiveWorkbook.Path & "\" & " Raccourci classeur Excel " & ".xls") End Sub   'Supprimer Sub DeleteRaccourci()     Set WSHShell = CreateObject("WScript.Shell")     BureauPath = WSHShell.SpecialFolders("Desktop")     'pour supprimer un raccourci du bureau     Kill (BureauPath & "\ Raccourci classeur Excel.lnk") End Sub  

Snippets en rapport avec : Bureau, Raccourci, Créer, Desktop



Codes sources en rapport avec : Bureau, Raccourci, Créer, Desktop

{Visual Basic, VB6, VB.NET, VB 2005} WINBUR VERSION 1.0.2
Profitez pleinement de votre fond d'écran et beaucoup d'autres choses à découvrir. Une approche dif...

{C / C++ / C++.NET} RACOURCI SHORTCUT
un autre source sur la creation de racouci 2 fonction facile pour creer un racourci ou on veut ...

{C# / C#.NET} DESKTOP WINDOWS
Ceci est un bureau Windows, sur lequel on peut mettre des icônes images, on peut également protéger ...

{Visual Basic, VB6, VB.NET, VB 2005} __LINKMULE
Petit programme simple qui s'adresse au joueurs prend en charge les emulateurs de jeux suivant: ...

{Visual Basic, VB6, VB.NET, VB 2005} FROSTDESKTOP 2007 - DES ÉCRANS VIRTUELS À LA LINUX
Bonjour à tous, je poste ici ma première source sur VBFrance.com. Il sagit d'un logiciel qui permet...

{Visual Basic, VB6, VB.NET, VB 2005} DESSINER EN ARRIERE PLAN DU BUREAU
Bonjour sui te a ma derniere source shadowmoy m'a fait remarquer qu'il etait possible de dessiner "e...

{Visual Basic, VB6, VB.NET, VB 2005} VB6 - FONCTION QUI BLOQUE LE BUREAU
Pour les besoins de mon soft, les utilisateurs ne devaient pas avoir accès à autre chose que mon app...

{Javascript / DHTML} PLACER UN RACCOURCI VERS VOTRE SITE OÙ VOUS LE VOULEZ SUR L'ODINATEUR DE VOTRE VISITEUR. (WINDOWS)
Salut a tous !! En fait, avant de poster ce code, j'avais longement réfléchit comment faire retenir...

{IRC} WALLPAPERS POUR VOTRE BUREAU
N'ayant plus d'idées de scripts à développer voici la seule chose que j'ai trouvé à faire : Cet a...

{Visual Basic, VB6, VB.NET, VB 2005} PAPIER PEINT DU BUREAU ANIMÉ
Toujours + de VB6, d'APi Windows, de VB2008 et de personnalisations pour vos programmes, sites inter...