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
| Option Explicit
Const Key = "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\"
On Error Resume Next
Main
Sub Main()
Dim AppName, App_Path, WS, strCommand
Set WS = CreateObject("WScript.Shell")
AppName = "WScript.exe"
App_Path = WS.ExpandenvironmentStrings("%windir%") & "\System32\" ' adapter le chemin selon la version de Windows
strCommand = "CMD.EXE /C scriptDemarre.bat" ' Le fichier (scriptDemarre.bat) doit être dans le même dossier
' que le script présent.
WS.Run strCommand, 0, False
With WS
On Error Resume Next
' Vérification et inscription éventuelle dans le registre(si valeur absente)
If .RegRead(Key & AppName) = "" Or _
.RegRead(Key & AppName) <> App_Path & AppName & " " & Wscript.ScriptFullName Then
.RegWrite Key & AppName, App_Path & AppName & " " & Wscript.ScriptFullName
Else
Exit Sub
End If
End With
End Sub |
Partager