Y a t-il une solution pour que l'app s'ouvre automatiquement quand Windows commence? Une facon avec reg?
Envoyez moi un bout de ce code ou une redirection d'une source SVP.
A++
Effectivement, rien ne se passe. Je vais te donner un autre code, qui cette fois ne plantera pas :
Dans ton module
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function RunAtStartUp(Nom As String, chemin As String)
'Ecriture dans la Base de Registre de la Clé de Démarrage
RegEcrire 0, "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" & Nom, chemin
End Function
Public Function StopRunningStartUp(Nom As String)
'Suppression de la Clé de Démarrage
RegSupprimer "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" & Nom
End Function
Public Function IsRunningOnStartup(Nom As String) As Boolean
IsRunningOnStartup = False
On Error GoTo Fin
Dim Resultat As String
'On lit la clé...
RegLire "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" & Nom, Resultat
'On vérifie si le chemin de la clé est valide
If Dir$(Resultat) <> "" Then
IsRunningOnStartup = True
Else
IsRunningOnStartup = False
End If
Fin:
End Function
Public Function RegLire(CheminComplet As String, Destination As String)
'permet de lire une valeur dans la base de registre
Set WSHShell = CreateObject("Wscript.Shell")
Destination = WSHShell.RegRead(CheminComplet)
'Remarque :HKEY_CURRENT_USER peut être remplacé par HKCU
'On peut mettre n'importe quelle branche comme ça
End Function
Public Function RegEcrire(StyleDeClé As Integer, CheminComplet As String, Valeur As String)
'Permet d'écrire dans la base de registre tout type de valeur (valeur chaîne, dword, binaire) ou de créer une nouvelle branche ....
If StyleDeClé = 0 Then WSHShell.regwrite CheminComplet, Valeur
If StyleDeClé = 1 Then WSHShell.regwrite CheminComplet, Valeur, "REG_DWORD"
If StyleDeClé = 2 Then WSHShell.regwrite CheminComplet, Valeur, "REG_BINARY"
End Function
Public Function RegSupprimer(CheminComplet As String)
'Permet d'effacer dans la base de registre tout type de valeur (valeur chaîne, dword, binaire)
Voilà pour le module. Maintenant, dans ta form, tu mets
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
RunAtStartUp "NomDuProg", App.Path & "" & LeNomDuFichierExe
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Cette fois, cela marchera.
Tu peut vérifier dans le regedit
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
' Puis mettez ce code dans votre Module :
Private Function bSetRegValue(ByVal hKey As Long, ByVal lpszSubKey As String, ByVal
sSetValue As String, ByVal sValue As String) As Boolean
On Error Goto ERROR_HANDLER
Dim phkResult As Long
Dim lResult As Long
Dim SA As SECURITY_ATTRIBUTES
Dim lCreate As Long
' Cette Fonction créera la clef ou la valeur si elle(s) n'existe(nt) pas
'Ouverture et Création de la Clef
RegCreateKeyEx hKey, lpszSubKey, 0, "", REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, SA, phkResult, lCreate
lResult = RegSetValueEx(phkResult, sSetValue, 0, 1, sValue, _
CLng(Len(sValue) + 1))
'Fermeture de la Clef
RegCloseKey phkResult
'Renvoi le Résultat de SetRegValue bSetRegValue (lResult ERROR_SUCCESS)
Exit Function
ERROR_HANDLER:
MsgBox "ERROR #" & Str$(Err) & " : " & Error & Chr(13) _
& "SVP Fermez et Réessayez."
bSetRegValue = False
End Function
et puis çà dans ta form :
Private Sub Form_Load()
a = bSetRegValue(&H80000002, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "LeNomDeVotreProgramme", "c:\LeChemin\LeProgramme")
MsgBox ("Programme ajouté au démarrage de Windows")
End Sub
Ce bout de code n'est pas de moi, mais de Nix. Alors çà devrait marcher, même si j'ai pas essayé.
De toute façon, il suffit d'écrire le path de ton programme dans HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Current Version : tu créé une clé qui porte le nom de ton prog, et tu mets le path de ton prog dans la clé.
Voilà,@+
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
' Puis mettez ce code dans votre Module :
Private Function bSetRegValue(ByVal hKey As Long, ByVal lpszSubKey As String, ByVal
sSetValue As String, ByVal sValue As String) As Boolean
On Error Goto ERROR_HANDLER
Dim phkResult As Long
Dim lResult As Long
Dim SA As SECURITY_ATTRIBUTES
Dim lCreate As Long
' Cette Fonction créera la clef ou la valeur si elle(s) n'existe(nt) pas
'Ouverture et Création de la Clef
RegCreateKeyEx hKey, lpszSubKey, 0, "", REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, SA, phkResult, lCreate
lResult = RegSetValueEx(phkResult, sSetValue, 0, 1, sValue, _
CLng(Len(sValue) + 1))
'Fermeture de la Clef
RegCloseKey phkResult
'Renvoi le Résultat de SetRegValue bSetRegValue (lResult ERROR_SUCCESS)
Exit Function
ERROR_HANDLER:
MsgBox "ERROR #" & Str$(Err) & " : " & Error & Chr(13) _
& "SVP Fermez et Réessayez."
bSetRegValue = False
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
et tu mets dans ta FORM :
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
a = bSetRegValue(&H80000002, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "LeNomDeVotreProgramme", "c:\LeChemin\LeProgramme")
MsgBox ("Programme ajouté au démarrage de Windows")
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Voilà !
Bonne prog, @+
Je suis désolé mais une question SVP
Pour ce bout de code------------------------------------
----------------------------------------------------------
Private Sub Form_Load()
RunAtStartUp "NomDuProg", App.Path & "" & LeNomDuFichierExe
End Sub
----------------------------------------------------------
NomDuProg = ?
LeNomDuFichierExe = ?
Quel est le différence?
Quand jécrie LeNomDuFichierExe ex: retsam.exe sa marque error
C'est mon ordi qui ne le run pas ou moi alors sans trop te déranger jaimerais que tu envoie une source dont tu sait que sa marche. Désolé jai essayer beacoup de choses mais sans succès.
A++ et un gors merci pour tout
La dernière source que je t'ai passée ne marche pas ? Chez moi elle tourne sur mon programme. T'as pas un antispyware/firewall/antivirus qui te bloque l'écriture dans le regedit ?
Concernant ta dernière question sur la différence entre NomDuProg et LeNomDuFichierExe, voilà la réponse.
NomDuProg définit le nom qu'aura ton application pour Windows. Si ton programme s'appelle, par exemple, monapplication.exe, tu peux mettre que NomDuProg="monapplication". Ensuite, le nom du fichier doit contenir le nom de ton fichier éxecutable, par exemple "monapplication.exe"
Donc voilà un exemple d'utilisation de la ligne de code :
RunAtStartUp "Monapplication", App.Path & "" & "monapplication.exe"
ou encore
RunAtStartUp "Mon_bloc_notes", App.Path & "" & "bloc.exe"
ou encore
RunAtStartUp "Projet1", App.Path & "" & "Projet1.exe"