Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Scrivere in una chiave del Regedit

    Come faccio a scrivere nel regedit nella chiave HKEY_LOCAL_MACHINE--->software-->microsoft-->windows-->currentversion-->run


    Per scrivere nella chiave dedicata al VB uso savesetting e per leggerla getsetting, ma come faccio a cambiare chiave?

    Fatemi sapere

    Juan

  2. #2
    Utente di HTML.it L'avatar di Gigi84
    Registrato dal
    May 2001
    Messaggi
    569
    fai una ricercan nel forum trovi tantissimi esempi!!


  3. #3
    Utente di HTML.it L'avatar di Mabi
    Registrato dal
    May 2002
    Messaggi
    1,245
    O anche nelle FAQ su Visual Basic del sito.
    Trovi un modulo molto utile.


  4. #4
    Vascello fantasma dei mentecatti nonchè baronetto della scara corona alcolica, piccolo spuccello di pezza dislessico e ubriaco- Colui che ha modificato l'orribile scritta - Gran Evacuatore Mentecatto - Tristo Mietitore Mentecatto chi usa uTonter danneggia anche te

  5. #5

    re

    se ho ben capito questo codice dovrebbe fare il caso tuo


    UTILIZZO
    '************************************************* **********

    '-----------------------------
    'cosi per creare la chiave:
    '-----------------------------
    nome_stringa$ = "Nome di Esempio"
    valore$ = "qualsiasi cosa"
    PutRegString HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run ", nome_stringa$, valore$
    'nome_stringa$, è il Nome stringa all'interno della chiave Run
    'valore$, è il valore associato a nome_stringa$

    '-----------------------------
    'cosi per leggere la chiave:
    '-----------------------------
    nome_stringa$ = "Nome di Esempio"
    valore$ = GetRegString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run ", nome_stringa$, "")

    'valore$ contiene "qualsiasi cosa"
    '************************************************* **********



    'INSERE IN UN MODULO
    '************************************************* **********
    Private Const REG_SZ = 1
    Private Const ERROR_SUCCESS = 0&

    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    Private 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
    Private 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

    'registro
    Enum regOptions
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
    HKEY_CURRENT_CONFIG = &H80000005 '*
    HKEY_DYN_DATA = &H80000006 '*
    HKEY_PERFORMANCE_DATA = &H80000004 '*
    End Enum

    'scrittura, eliminazione nel registro di configurazione
    Sub PutRegString(hKey As regOptions, strPath As String, strValue As String, strData As String)
    Dim hCurKey As Long
    Dim lRegResult As Long

    lRegResult = RegCreateKey(hKey, strPath, hCurKey)

    lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData))

    If lRegResult <> ERROR_SUCCESS Then
    MsgBox "Scrittura nel registro fallita", vbCritical
    End If

    lRegResult = RegCloseKey(hCurKey)
    End Sub

    'lettura dal registro di configurazione
    Public Function GetRegString(hKey As regOptions, strPath As String, strValue As String, Optional Default As String) As String
    Dim hCurKey As Long
    Dim lValueType As Long
    Dim strBuffer As String
    Dim lDataBufferSize As Long
    Dim intZeroPos As Integer
    Dim lRegResult As Long

    ' Setup valore default
    If Not IsEmpty(Default) Then
    GetRegString = Default
    Else
    GetRegString = ""
    End If

    ' Apre la key e legge la lunghezza della stringa
    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, lValueType, ByVal 0&, lDataBufferSize)

    If lRegResult = ERROR_SUCCESS Then

    If lValueType = REG_SZ Then
    ' inizializza il buffer della stringa e la sostituisce
    strBuffer = String(lDataBufferSize, " ")
    lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, ByVal strBuffer, lDataBufferSize)

    ' formato stringa
    intZeroPos = InStr(strBuffer, Chr$(0))
    If intZeroPos > 0 Then
    GetRegString = Left$(strBuffer, intZeroPos - 1)
    Else
    GetRegString = strBuffer
    End If

    End If

    Else
    ' ci sono probblemi....
    End If

    lRegResult = RegCloseKey(hCurKey)
    End Function
    '************************************************* **********

    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.