Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CONFIG PAR BD REGISTRE


Information sur la source

Description

Cliquez pour voir la capture en taille normale
A ziueter la source je me sert de la bd de registre pour la config de mon exe
 

Source

  • 'API:
  • ' -----------------
  • ' ADVAPI32
  • ' -----------------
  • ' function prototypes, constants, and type definitions
  • ' for Windows 32-bit Registry API
  • Public Const HKEY_CLASSES_ROOT = &H80000000
  • Public Const HKEY_CURRENT_USER = &H80000001
  • Public Const HKEY_LOCAL_MACHINE = &H80000002
  • Public Const HKEY_USERS = &H80000003
  • Public Const HKEY_PERFORMANCE_DATA = &H80000004
  • Public Const ERROR_SUCCESS = 0&
  • ' Registry API prototypes
  • Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
  • Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  • Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
  • Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
  • Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
  • Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
  • Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
  • Public Const REG_SZ = 1 ' Unicode nul terminated string
  • Public Const REG_DWORD = 4 ' 32-bit number
  • Public Sub savekey(Hkey As Long, strPath As String)
  • Dim keyhand&
  • r = RegCreateKey(Hkey, strPath, keyhand&)
  • r = RegCloseKey(keyhand&)
  • End Sub
  • Public Function getstring(Hkey As Long, strPath As String, strValue As String)
  • Dim keyhand As Long
  • Dim datatype As Long
  • Dim lResult As Long
  • Dim strBuf As String
  • Dim lDataBufSize As Long
  • Dim intZeroPos As Integer
  • r = RegOpenKey(Hkey, strPath, keyhand)
  • lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
  • If lValueType = REG_SZ Then
  • strBuf = String(lDataBufSize, " ")
  • lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
  • If lResult = ERROR_SUCCESS Then
  • intZeroPos = InStr(strBuf, Chr$(0))
  • If intZeroPos > 0 Then
  • getstring = Left$(strBuf, intZeroPos - 1)
  • Else
  • getstring = strBuf
  • End If
  • End If
  • End If
  • End Function
  • Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strdata As String)
  • Dim keyhand As Long
  • Dim r As Long
  • r = RegCreateKey(Hkey, strPath, keyhand)
  • r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
  • r = RegCloseKey(keyhand)
  • End Sub
  • Function getdword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
  • Dim lResult As Long
  • Dim lValueType As Long
  • Dim lBuf As Long
  • Dim lDataBufSize As Long
  • Dim r As Long
  • Dim keyhand As Long
  • r = RegOpenKey(Hkey, strPath, keyhand)
  • ' Get length/data type
  • lDataBufSize = 4
  • lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
  • If lResult = ERROR_SUCCESS Then
  • If lValueType = REG_DWORD Then
  • getdword = lBuf
  • End If
  • 'Else
  • ' Call errlog("GetDWORD-" & strPath, False)
  • End If
  • r = RegCloseKey(keyhand)
  • End Function
  • Function SaveDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
  • Dim lResult As Long
  • Dim keyhand As Long
  • Dim r As Long
  • r = RegCreateKey(Hkey, strPath, keyhand)
  • lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
  • 'If lResult <> error_success Then Call errlog("SetDWORD", False)
  • r = RegCloseKey(keyhand)
  • End Function
  • Public Function DeleteKey(ByVal Hkey As Long, ByVal strKey As String)
  • Dim r As Long
  • r = RegDeleteKey(Hkey, strKey)
  • End Function
  • Public Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
  • Dim keyhand As Long
  • r = RegOpenKey(Hkey, strPath, keyhand)
  • r = RegDeleteValue(keyhand, strValue)
  • r = RegCloseKey(keyhand)
  • End Function
  • 'Code:
  • Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  • Private Declare Function GetTickCount Lib "kernel32" () As Long
  • Option Explicit
  • Private Sub Command2_Click()
  • Unload Me
  • End Sub
  • Private Sub File_Click()
  • Dim current As Integer
  • Dim i As Integer
  • Dim intIndex As Integer
  • Dim iStart As Integer
  • Dim FileNames$()
  • Dim sFname As String
  • Dim iEndPath As Integer
  • With CommonDialog1
  • .MaxFileSize = 2048 ' Définir de façon appropriée
  • .FileName = ""
  • .Filter = "Tous les fichiers|*.*"
  • .Flags = cdlOFNExplorer
  • .ShowOpen
  • sFname = .FileName & vbNullChar
  • End With
  • iEndPath = 1
  • iStart = iEndPath + 1
  • iEndPath = InStr(iEndPath + 1, sFname, "\")
  • ReDim Preserve FileNames(0)
  • ' détermine si le répertoire racine a été sélectionné
  • ' (conserve le "\")
  • FileNames(0) = Mid(sFname, 1, iStart - 1)
  • intIndex = 1
  • For i = iStart To Len(sFname)
  • If Mid(sFname, i, 1) = vbNullChar Then
  • ReDim Preserve FileNames(intIndex)
  • FileNames(intIndex) = Mid(sFname, iStart, i - iStart)
  • iStart = i + 1
  • intIndex = intIndex + 1
  • End If
  • Next i
  • For i = 0 To UBound(FileNames)
  • Exe.Text = "c" & FileNames(i)
  • Next i
  • End Sub
  • Private Sub Form_Load()
  • Dim strString, temps As String
  • 'Get a String out the Registry
  • Exe.Text = getstring(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows", "Davwoodexe")
  • sec.Text = getstring(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows", "Davwoodsec")
  • If sec.Text = "" Then sec.Text = "0"
  • temps = sec.Text
  • Timer1.Interval = temps * 1000
  • Timer1.Enabled = True
  • End Sub
  • Private Sub Stp_Click()
  • Timer1.Enabled = False
  • End Sub
  • Private Sub Timer1_Timer()
  • Shell (Exe.Text), vbNormalFocus
  • Unload Me
  • End Sub
  • Private Sub Valid_Click()
  • Dim r
  • Set r = CreateObject("WScript.Shell")
  • r.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Davwoodexe", Exe.Text
  • r.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Davwoodsec", sec.Text
  • End Sub
'API:
' -----------------
' ADVAPI32
' -----------------
' function prototypes, constants, and type definitions
' for Windows 32-bit Registry API

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&

' Registry API prototypes

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Public Const REG_SZ = 1                         ' Unicode nul terminated string
Public Const REG_DWORD = 4                      ' 32-bit number
Public Sub savekey(Hkey As Long, strPath As String)
Dim keyhand&
r = RegCreateKey(Hkey, strPath, keyhand&)
r = RegCloseKey(keyhand&)
End Sub
Public Function getstring(Hkey As Long, strPath As String, strValue As String)
Dim keyhand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
r = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
    strBuf = String(lDataBufSize, " ")
    lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
    If lResult = ERROR_SUCCESS Then
        intZeroPos = InStr(strBuf, Chr$(0))
        If intZeroPos > 0 Then
            getstring = Left$(strBuf, intZeroPos - 1)
        Else
            getstring = strBuf
        End If
    End If
End If
End Function


Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub


Function getdword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBuf As Long
Dim lDataBufSize As Long
Dim r As Long
Dim keyhand As Long

r = RegOpenKey(Hkey, strPath, keyhand)

 ' Get length/data type
lDataBufSize = 4
    
lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)

If lResult = ERROR_SUCCESS Then
    If lValueType = REG_DWORD Then
        getdword = lBuf
    End If
'Else
'    Call errlog("GetDWORD-" & strPath, False)
End If

r = RegCloseKey(keyhand)
    
End Function

Function SaveDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
    Dim lResult As Long
    Dim keyhand As Long
    Dim r As Long
    r = RegCreateKey(Hkey, strPath, keyhand)
    lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
    'If lResult <> error_success Then Call errlog("SetDWORD", False)
    r = RegCloseKey(keyhand)
End Function

Public Function DeleteKey(ByVal Hkey As Long, ByVal strKey As String)
Dim r As Long
r = RegDeleteKey(Hkey, strKey)
End Function

Public Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
r = RegOpenKey(Hkey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function
'Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Option Explicit

Private Sub Command2_Click()
Unload Me
End Sub
Private Sub File_Click()
Dim current As Integer
Dim i As Integer
Dim intIndex As Integer
Dim iStart As Integer
Dim FileNames$()
Dim sFname As String
Dim iEndPath As Integer

With CommonDialog1
.MaxFileSize = 2048 ' Définir de façon appropriée
.FileName = ""
.Filter = "Tous les fichiers|*.*"
.Flags = cdlOFNExplorer
.ShowOpen
sFname = .FileName & vbNullChar
End With

iEndPath = 1
iStart = iEndPath + 1
iEndPath = InStr(iEndPath + 1, sFname, "\")
ReDim Preserve FileNames(0)
' détermine si le répertoire racine a été sélectionné
' (conserve le "\")
FileNames(0) = Mid(sFname, 1, iStart - 1)

intIndex = 1
For i = iStart To Len(sFname)
If Mid(sFname, i, 1) = vbNullChar Then
ReDim Preserve FileNames(intIndex)
FileNames(intIndex) = Mid(sFname, iStart, i - iStart)
iStart = i + 1
intIndex = intIndex + 1
End If
Next i

For i = 0 To UBound(FileNames)
Exe.Text = "c" & FileNames(i)
Next i

End Sub

Private Sub Form_Load()
Dim strString, temps As String
'Get a String out the Registry
Exe.Text = getstring(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows", "Davwoodexe")
sec.Text = getstring(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows", "Davwoodsec")
If sec.Text = "" Then sec.Text = "0"
temps = sec.Text
Timer1.Interval = temps * 1000
Timer1.Enabled = True
End Sub
Private Sub Stp_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Shell (Exe.Text), vbNormalFocus
Unload Me
End Sub
Private Sub Valid_Click()
Dim r
Set r = CreateObject("WScript.Shell")
r.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Davwoodexe", Exe.Text
r.RegWrite "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Davwoodsec", sec.Text
End Sub

Conclusion

A vos remarques
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Janvier 2009
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,265 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.