IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Creation Raccourci sur le bureau [Batch]


Sujet :

Scripts/Batch

  1. #1
    Membre actif Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Points : 278
    Points
    278
    Par défaut Creation Raccourci sur le bureau
    Bonjour,

    j'ai créé un script Batch qui créé un raccourci sur le bureau. Cependant je n'arrive pas a faire pointer le .ico présent dans le WorkingDirectory sur le raccourci.

    Le raccourci garde l’icône standard de Windows.

    Merci de votre aide.


    Code bat : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Set oWS = WScript.CreateObject("WScript.Shell")
       sLinkFile = "FermetureSession.lnk"
       Set oLink = oWS.CreateShortcut(sLinkFile)
     
       oLink.TargetPath = "C:\Program Files\monAppli\Fermeture Session.cmd"
       '  oLink.Description = "Ferme la session en cours"
       '  oLink.IconLocation = "C:\Program Files\monAppli\icon.ico"
       '  oLink.WindowStyle = "1"
       '  oLink.WorkingDirectory = "C:\Program Files\monAppli"
       oLink.Save

    J'ai fouillé un peu sur les divers forums le code semble OK, je ne comprend pas pourquoi le raccourci généré ne prend pas l’icône ...

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    Inspirez-vous de ce
    Code BAT : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    @echo off
    setlocal enabledelayedexpansion
    Set "Delay2Shutdown=600"
    Set "Delay2Reboot=600"
    Set TmpFile=%Temp%\TmpFile.txt
    Set Resultat=%Temp%\KillResult.txt
    Set "MyKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
    If Exist %TmpFile% Del %TmpFile%
    If Exist %Resultat% Del %Resultat%
    Set "MyFile=%~f0"
    Set "ShorcutName=Shtutdown_Reboot"
    (
    echo Call Shortcut("%MyFile%","%ShorcutName%"^)
    echo ^'**********************************************************************************************^)
    echo Sub Shortcut(CheminApplication,Nom^)
    echo    Dim objShell,DesktopPath,objShortCut,MyTab
    echo    Set objShell = CreateObject("WScript.Shell"^)
    echo    MyTab = Split(CheminApplication,"\"^)
    echo    If Nom = "" Then
    echo    Nom = MyTab(UBound(MyTab^)^)
    echo    End if
    echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
    echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
    echo    objShortCut.TargetPath = Dblquote(CheminApplication^)
    echo    ObjShortCut.IconLocation = "Shell32.dll,44"
    echo    objShortCut.Save
    echo End Sub
    echo ^'**********************************************************************************************
    echo ^'Fonction pour ajouter les doubles quotes dans une variable
    echo Function DblQuote(Str^)
    echo    DblQuote = Chr(34^) ^& Str ^& Chr(34^)
    echo End Function
    echo ^'**********************************************************************************************
    ) > %temp%\Shortcutme.vbs
    Start /Wait %temp%\Shortcutme.vbs
    Del %temp%\Shortcutme.vbs
    ::****************************************************************************************************
    Title Dynamic Menu (Shutdown/Reboot) (Start/Kill Process) by Hackoo 2016
    :menuLOOP
    Color 1E & Mode con cols=78 lines=20
    echo(
    echo(       =============================Menu==============================
    echo(
    for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo         %%A  %%B
    echo(
    echo(       ===============================================================
    set choice=
    echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
    echo( & call :menu_[%choice%]
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[1] (ARRET)/(SHUTDOWN)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 3
    echo %x% Please Wait for a while .... 
    TimeOut /T 1 /NoBreak>nul
    shutdown -s -t %Delay2Shutdown% -c "Your machine will shutdown in 5 minutes." -f 
    GOTO:menuLOOP
    ::********************************************************************************************4
    :menu_[2] (REDEMARRAGE)/(REBOOT)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 3
    echo %x% Please Wait for a while .....
    TimeOut /T 1 /NoBreak>nul
    shutdown -r -t %Delay2Reboot% -c "Your machine will reboot in 5 minutes." -f 
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[3] (APPLICATION PAS DE REPONSE)/(APPLICATION NOT RESPONDING)
    cls & color 0A
    Call:SkipLine 10
    Call:Tab 3
    echo %x% Please Wait for a while .. Launching  ...
    TimeOut /T 1 /NoBreak>nul
    Start "Killing not responding application" cmd /k taskkill.exe /f /fi "status eq not responding" >> %Resultat%
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[4] (ANNULER ARRET/REDEMARRAGE)/(CANCEL SHUTDOWN/REBOOT)
    cls & color 0A
    Call:SkipLine 5
    Call:Tab 7
    echo %x% Please Wait for a while ....
    TimeOut /T 1 /NoBreak>nul
    (
        echo    Set Ws = CreateObject("wscript.shell"^)
        echo    Answ = MsgBox("Did you want to cancel the scheduled reboot of your the computer ?"_
        echo ,VbYesNo+VbQuestion,"Did you want to cancel the scheduled reboot of your the computer ?"^)
        echo    If Answ = VbYes then 
        echo        Return = Ws.Run("cmd /c Shutdown -a",0,True^)
        echo    Else
        echo        wscript.Quit(1^)
        echo    End If
    )>"%tmp%\%~n0.vbs"
    Start "" "%tmp%\%~n0.vbs"
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[5] (START PROCESS/MULTI-PROCESS)/(LANCER PROSESSUS)
    cls & color 0A
    echo(
    echo      Enter the process name or processes names separated by a space
    echo(
    Set /p "MyProcess=What process(es) do you want to Start ?>"
    cls  
    Call:SkipLine 8
    Call:Tab 6
    echo %x% The process(es) "%MyProcess%" is launched ...
    TimeOut /T 1 /NoBreak>nul
    For %%a in (%Myprocess%) Do (Start %%a)
    GOTO :menuLOOP
    ::********************************************************************************************
    :menu_[6] (KILL PROCESS/MULTI-PROCESS)/(TUER PROCESSUS)
    Title Process Killer by Hackoo 2016
    cls & color 0B
    echo(
    echo     Enter the process name or processes names separated by a space
    echo(
    set /p "process=What process(es) do you want to kill ?>"
    cls & color 0C
    Title Killing "%process%" ...
    Call:SkipLine 8
    Call:Tab 7
    echo %x% Killing "%process%" ...
    echo(
    echo %date% *** %time% >> %TmpFile%
    For %%a in (%process%) Do Call :KillMyProcess %%a
    Cmd /U /C Type %TmpFile% > %Resultat%
    Start %Resultat%
    GOTO :menuLOOP
    ::******************************************************************************************
    :menu_[7] (Disable execution for one application choosen by the user)
    Mode con cols=90 lines=15 & Cls & color 0C
    echo(
    echo Enter Application name with its extension to block and disable it like "Chrome.exe"
    echo(
    Set /p "App=Enter Application name to block and diable it > "
    IF [%App%] == [] GOTO:menuLOOP
    REG ADD "%MyKey%\%App%" /f
    REG ADD "%MyKey%\%App%" /v Debugger /t REG_SZ /d Block /f
    Start "" "%App%"
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[8] (Enable execution for one application choosen by the user)
    Mode con cols=90 lines=15 & Cls & color 0A
    echo(
    echo Enter Application name with its extension to unblock and enable it like "Chrome.exe"
    echo(
    Set /p "App=Enter Application name to unblock and enable it> "
    IF [%App%] == [] GOTO:menuLOOP
    REG ADD "%MyKey%\%App%" /f
    REG ADD "%MyKey%\%App%" /v Debugger /t REG_SZ /d "" /f
    Start "" "%App%"
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[9] (Disable and block the execution of all Browsers)
    Mode con cols=90 lines=15 & Cls & color 0C
    Set Browsers=iexplore.exe firefox.exe chrome.exe opera.exe
    For %%a in (%Browsers%) Do Call :BlockExecution %%a
    GOTO:menuLOOP
    ::*****************************************************************************************
    :menu_[10] Enable and unblock the execution of all Browsers)
    Mode con cols=90 lines=15 & Cls & color 0A
    Set Browsers=iexplore.exe firefox.exe chrome.exe opera.exe
    For %%a in (%Browsers%) Do Call :UnBlockExecution %%a
    GOTO:menuLOOP
    ::********************************************************************************************
    :menu_[11] Take screenshots of your applications (Windows 7,8,10)
    Start "" snippingtool.exe
    GOTO :menuLOOP
    ::*****************************************************************************************
    :BlockExecution
    REG ADD "%MyKey%\%~nx1" /f
    REG ADD "%MyKey%\%~nx1" /v Debugger /t REG_SZ /d Block /f
    Exit /b
    ::*****************************************************************************************
    :UnBlockExecution
    REG ADD "%MyKey%\%~nx1" /f
    REG ADD "%MyKey%\%~nx1" /v Debugger /t REG_SZ /d "" /f
    Exit /b
    ::*****************************************************************************************
    :Tab
    set "x="
    For /L %%I In (1,1,%1) Do Set "x=!x!    "
    REM                                  ^-- this is a TAB
    goto :eof
    ::*********************************************************************************************
    :SkipLine
    For /L %%I In (1,1,%1) Do Echo(
    Goto:Eof
    ::*********************************************************************************************
    :KillMyProcess
    Taskkill /IM "%~n1.exe" /F >> %TmpFile% 2>&1
    echo ***************************************************************************** >> %TmpFile%
    exit /b
    ::*****************************************************************************************

  3. #3
    Membre actif Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Points : 278
    Points
    278
    Par défaut
    Bonjour,

    merci pour votre réponse rapide !

    J'ai réussi en utilisant le code suivant :
    Code BAT : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    set WshShell = WScript.CreateObject("WScript.Shell")
             strDesktop = WshShell.SpecialFolders("Desktop")
             set oShellLink = WshShell.CreateShortcut(strDesktop & "\Fermeture de Session.lnk")
             oShellLink.TargetPath = "C:\Program Files\monAppli\Fermeture Session.cmd"
             oShellLink.WindowStyle = 1
             oShellLink.IconLocation = "C:\Program Files\monAppli\icon.ico,0"
             oShellLink.Description = "Fermeture de la session"
             oShellLink.WorkingDirectory = "C:\Program Files\monAppli\"
             oShellLink.Save

    Je n'ai pas utilisé le même objet que vous mais la propertie IconLocation m'a aidée, en effet je n'avais pas mis d'index !! J'ai donc remis l'emplacement de l'icône et utilisé l'index 0 !

    Merci pour votre aide, sujet résolu.

    Je laisse le code pour ceux qui auraient besoin de déployer via une console la création d'un raccourci sur le bureau via un VBS.

    Bonne journée.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Creation de Raccourcis sur le Bureau
    Par Danyel dans le forum VB.NET
    Réponses: 5
    Dernier message: 26/03/2008, 19h40
  2. raccourcis sur le bureau
    Par Galkir dans le forum C++Builder
    Réponses: 9
    Dernier message: 23/06/2006, 11h26
  3. Créer un raccourci sur le bureau
    Par NdmaX dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 13/04/2006, 17h21
  4. Raccourci sur le bureau
    Par AlDel dans le forum API, COM et SDKs
    Réponses: 2
    Dernier message: 07/03/2005, 17h07
  5. Raccourci sur le bureau
    Par senateur dans le forum Langage
    Réponses: 7
    Dernier message: 05/09/2002, 15h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo