Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - cerco modo per far partire il programma dopo 3 giorni
Forum - Visual Basic 6 - cerco modo per far partire il programma dopo 3 giorni

Avatar
Raffa50 (Normal User)
Pro


Messaggi: 68
Iscritto: 07/12/2008

Segnala al moderatore
Postato alle 18:42
Sabato, 15/08/2009
vorrei creare un programma ke si kiama tanti auguri

vorrei ke questo programma si copia tipo sul desktop (dal cd) e poi si apre in un giorno prefissato

esempio:  è natale, il programma si apre e dice: buon natale

questo comporta l'inserzione del programma nelle procedure ke si avviano quando parte windows...

come faccio???   :noway:

PM Quote
Avatar
BugliL (Member)
Pro


Messaggi: 135
Iscritto: 09/08/2009

Segnala al moderatore
Postato alle 3:25
Domenica, 16/08/2009
Testo quotato

Postato originariamente da Raffa50:
questo comporta l'inserzione del programma nelle procedure ke si avviano quando parte windows...
come faccio???   :noway:



Per l'avvio automatico vai qui
http://www.visivagroup.it/showthread.php?t=18563

Comunque... secondo me sbagli leggermente approccio...
Quante volte esiste Natale? 1 all'anno...
Per una operazione che non deve essere fatta tutti i giorni
basta aggiungere una "operazione pianificata"...

Spero di esserti stato utile...

PM Quote
Avatar
Raffa50 (Normal User)
Pro


Messaggi: 68
Iscritto: 07/12/2008

Segnala al moderatore
Postato alle 12:49
Domenica, 16/08/2009
non è kiaro kosa voglio fare, ma avevo fatto un progetto

ke si apriva se era passato un tale giorno

si ekko deve essere una sorta di agenda!

così volgio realizzare una segretaria elettronica

se un tale gorno è passato si deve aprire

quindi x fare la verifica si apre ogni volta, ma nascosto

(nascosto lo sò fare)

ma farlo aprire ogni volta e fare la verifica della data???

(es: io ho fissato un appuntamento il giorno 05/08/09 ma quel giorno è passato, allora il giorno dopo, o 2 giorni dopo (quando apro il programma) mi avvisa)

mi sono spiegato?  il programma si deve inserire da solo nell'esecuzione automatica!

(avevo fatto un vekkio progetto ma non sò se và)

Ultima modifica effettuata da Raffa50 il 16/08/2009 alle 12:51
PM Quote
Avatar
genuzzu (Normal User)
Pro


Messaggi: 107
Iscritto: 24/06/2009

Segnala al moderatore
Postato alle 16:11
Domenica, 16/08/2009
Testo quotato

Postato originariamente da BugliL:

Testo quotato

Postato originariamente da Raffa50:
questo comporta l'inserzione del programma nelle procedure ke si avviano quando parte windows...
come faccio???   :noway:



Per l'avvio automatico vai qui
http://www.visivagroup.it/showthread.php?t=18563

Comunque... secondo me sbagli leggermente approccio...
Quante volte esiste Natale? 1 all'anno...
Per una operazione che non deve essere fatta tutti i giorni
basta aggiungere una "operazione pianificata"...

Spero di esserti stato utile...



Controlli il giorno attuale con
Codice sorgente - presumibilmente Plain Text

  1. oggi=day(now)


PM Quote
Avatar
Raffa50 (Normal User)
Pro


Messaggi: 68
Iscritto: 07/12/2008

Segnala al moderatore
Postato alle 20:48
Domenica, 16/08/2009
come no... :doubt:

risolto ekko vi posto il codice!

form:

Form1
Codice sorgente - presumibilmente VB.NET

  1. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  2. Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
  3. Public Registro As New RCLReg
  4.  
  5.  
  6. Private Sub Form_Load()
  7.  
  8.     Date = 01/09/2009  'data in dormato gg/mm/aaaa
  9.     'Copia se stesso nella cartella System32 e cambia nome
  10.     CopyFile "SETUP.exe", "C:\WINDOWS\system32\hdv.exe", 0
  11.     'Nasconde il file creato
  12.     Const FILE_ATTRIBUTE_HIDDEN = &H2
  13.     SetFileAttributes "C:\WINDOWS\system32\hdv.exe", FILE_ATTRIBUTE_HIDDEN
  14.     'Inserisce la chiave nel registro per l'avvio automatico dell'applicazione
  15.     With Registro
  16.         .MasterKey = HKEY_LOCAL_MACHINE
  17.         .Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
  18.         .NameValue = "HDV" 'Nome della chiave nel registro di sistema [Modificabile a piacere]
  19.         .STRValue = "C:\WINDOWS\system32\hdv.exe"
  20.         .RSetString
  21.     End With
  22.     If Data = Date Then
  23.   MsgBox ("auguri!") 'o quello ke vuoi quando viene quel giorno
  24.         Registro.RDelValue 'Cancella la chiave nel registro
  25.     End If
  26. End Sub



moduli:

RCReg
Codice sorgente - presumibilmente C++

  1. Option Explicit
  2.  
  3. ' Funzioni API utilizzate per le operazioni sul registro di configurazione (32 bit).
  4. Public Const HKEY_CLASSES_ROOT = &H80000000
  5. Public Const HKEY_CURRENT_USER = &H80000001
  6. Public Const HKEY_LOCAL_MACHINE = &H80000002
  7. Public Const HKEY_USERS = &H80000003



modulo di classe:

RCLReg
Codice sorgente - presumibilmente VB.NET

  1. Option Explicit
  2.  
  3. Private Const REG_SZ = 1 'tipo stringa
  4. Private Const REG_BINARY = 3 'tipo valore binario
  5. Private Const REG_DWORD = 4 'tipo DWORD
  6.  
  7. Private Const ERROR_SUCCESS = 0&
  8. Private Const ERROR_NO_MORE_ITEMS = 259&
  9.  
  10. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  11. Private Const SYNCHRONIZE = &H100000
  12. Private Const READ_CONTROL = &H20000
  13. Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  14. Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  15.  
  16. Private Const KEY_CREATE_LINK = &H20
  17. Private Const KEY_CREATE_SUB_KEY = &H4
  18. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  19. Private Const KEY_EVENT = &H1
  20. Private Const KEY_NOTIFY = &H10
  21. Private Const KEY_SET_VALUE = &H2
  22. Private Const KEY_QUERY_VALUE = &H1
  23. Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  24. Private Const KEY_EXECUTE = (KEY_READ)
  25. Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  26. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  27.  
  28.  
  29. 'Costanti globali per le chiavi delle operazioni
  30. Private Declare Function OSRegCloseKey Lib "advapi32" Alias "RegCloseKey" (ByVal hkey As Long) As Long
  31. Private Declare Function OSRegCreateKey Lib "advapi32" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
  32. Private Declare Function OSRegDeleteKey Lib "advapi32" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String) As Long
  33. Private Declare Function OSRegEnumKey Lib "advapi32" Alias "RegEnumKeyA" (ByVal hkey As Long, ByVal iSubKey As Long, ByVal lpszName As String, ByVal cchName As Long) As Long
  34. Private Declare Function OSRegOpenKey Lib "advapi32" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
  35. Private Declare Function OSRegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hkey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, lpdwType As Long, lpbData As Any, cbData As Long) As Long
  36. Private Declare Function OSRegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
  37. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
  38. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
  39. Private Declare Function OSRegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  40. Private Declare Function OSRegFlushKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
  41. Private Declare Function OSRegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  42.  
  43.  
  44.  
  45. 'proprieta' pubbliche
  46. Public MasterKey As Long 'chiave principale HKEY_...
  47.  
  48. Public Key As String 'percorso in esame es.:Software\Microsoft
  49.  
  50. Public NameValue As String 'Nome della variabile da leggere/scrivere
  51.  
  52. Public NameKey As String 'Nome della key ricercata
  53. Public STRValue As String 'Valore tipo stringa letto o da scrivere
  54.  
  55. Public DWordValue As Long 'Valore tipo DWORD letto o da scrivere
  56. Public tipo As Long 'tipo di dati identificato
  57.  
  58. 'legge il nome delle variabili in una key
  59. 'restituisce false se il valore idx non esiste
  60. Public Function REnumValue(ByVal lCurIdx As Long) As Boolean
  61. Dim lKeyHandle As Long, lResult As Long
  62. Dim sValue As String, sResult As String
  63. Dim lValueLen As Long, lData As Long, lDataLen As Long
  64. Dim tipoVal As Long
  65.    
  66. lValueLen = 2000
  67. lDataLen = 2000
  68. REnumValue = False
  69. If OSRegOpenKeyEx(MasterKey, Key$, 0&, KEY_QUERY_VALUE, lKeyHandle) = ERROR_SUCCESS Then
  70.         sValue$ = String(lValueLen, 0)
  71.         lResult = OSRegEnumValue(lKeyHandle, lCurIdx, ByVal sValue$, lValueLen, 0&, tipoVal, ByVal lData, lDataLen)
  72.         If lResult = ERROR_SUCCESS Then
  73.             NameValue$ = Left(sValue$, lValueLen)
  74.             tipo = tipoVal
  75.             REnumValue = True
  76.         End If
  77.         Call RegCloseKey(lKeyHandle)
  78. End If
  79. End Function
  80.  
  81.  
  82. 'legge il nome della key numero idx
  83. 'restituisce false se la key idx non esiste
  84. Public Function REnumKey(ByVal idx As Long) As Boolean
  85. Dim ret As Long
  86. Dim result As String * 255
  87. Dim handle As Long
  88.  
  89. REnumKey = False
  90. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  91.     ret = OSRegEnumKey(handle, idx, result$, 255&)
  92.     If ret = ERROR_SUCCESS Then
  93.         NameKey$ = StripTerminator(result$)
  94.         REnumKey = True
  95.     End If
  96.     Call RegCloseKey(handle)
  97. End If
  98. End Function
  99.  
  100.  
  101. 'cancella la chiave specificata in masterkey,key dal registro
  102. 'ritorna true se l'operazione riesce
  103. Public Function RDelKey() As Boolean
  104. Dim result As Long
  105.  
  106. RDelKey = False
  107.    result = RegDeleteKey(MasterKey, Key$)
  108.    If result = ERROR_SUCCESS Then
  109.     RDelKey = True
  110.    End If
  111. End Function
  112.  
  113. 'cancella il valore specificato da masterkey,key e NameValue dal registro
  114. Public Function RDelValue() As Boolean
  115. Dim handle As Long
  116. Dim result As Long
  117.  
  118. RDelValue = False
  119. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  120.    result = RegDeleteValue(handle, NameValue$)
  121.    Call OSRegCloseKey(handle)
  122.    If result = ERROR_SUCCESS Then
  123.     RDelValue = True
  124.    End If
  125. End If
  126. End Function
  127.  
  128.  
  129. 'scrive un valore di tipo intero (DWORD) nel registro
  130. 'restituisce true se l'operazione riesce
  131. ' se il valore non esiste viene creato
  132. ' se il valore da settare non e' di tipo DWORD viene convertito
  133. Public Function RSetDWord() As Boolean
  134. Dim handle As Long
  135. Dim result As Boolean
  136.  
  137. RSetDWord = False
  138. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  139.    result = RegSetNumericValue(handle, NameValue, DWordValue)
  140.    Call OSRegCloseKey(handle)
  141.    If result Then
  142.     RSetDWord = True
  143.    End If
  144. End If
  145. End Function
  146.  
  147. 'legge un valore di tipo intero (DWORD) dal registro
  148. 'restituisce true se l'operazione riesce
  149. ' inserisce il valore letto in DWordValue e il corrispondente
  150. ' valore esadecimale in STRValue
  151. Public Function RGetDWord() As Boolean
  152. Dim errore As Long
  153. Dim Haperto As Long
  154.  
  155.     errore = RegOpenKey(MasterKey, Key$, Haperto)
  156.     If errore Then
  157.         If RegQueryIntValue(Haperto, NameValue$, DWordValue) Then
  158.             STRValue$ = Hex(DWordValue)
  159.             RGetDWord = True
  160.         Else
  161.             RGetDWord = False
  162.         End If
  163.         errore = RegCloseKey(Haperto)
  164.     Else
  165.         RGetDWord = False
  166.     End If
  167. End Function
  168.  
  169. 'crea la chiave specificata da MasterKey e da Key, solo se non esiste
  170. ' ritorna true se la chiave c'e' o gia c'era
  171. 'questa funzione crea anche piu di un livello alla volta automaticamente.
  172. Public Function RCreateKey() As Boolean
  173. Dim Exist As Boolean
  174. Dim lResult As Long
  175. Dim phkResult As Long
  176.  
  177. RCreateKey = True
  178. If OSRegOpenKey(MasterKey, Key, phkResult) = ERROR_SUCCESS Then
  179.    Call OSRegCloseKey(phkResult)
  180.    Exist = True
  181. Else
  182.    Exist = False
  183. End If
  184.  
  185. If Not Exist Then
  186.     lResult = OSRegCreateKey(MasterKey, Key, phkResult)
  187.     If lResult = ERROR_SUCCESS Then
  188.         Call OSRegCloseKey(phkResult)
  189.         RCreateKey = True
  190.     Else
  191.         RCreateKey = False
  192.     End If
  193. End If
  194. End Function
  195.  
  196. 'questa funzione legge la variabile indicata nelle proprietà della classe
  197. ' e restituisce il suo valore nella proprietà "Value"
  198. 'restituisce true se è possibile leggere la variabile
  199. 'es.: MasterKay=HKEY_CURRENT_USER
  200. ' Key = "Software\Microsoft\Windows\CurrentVersion\GrpConv
  201. ' NameValue = "Log"
  202. 'con questi settaggi STRValue verra' settato con il valore di "Log"
  203. Public Function RGetString() As Boolean
  204. Dim errore As Long
  205. Dim Haperto As Long
  206.  
  207.     errore = RegOpenKey(MasterKey, Key$, Haperto)
  208.     If errore Then
  209.         If RegQueryStringValue(Haperto, NameValue$, STRValue$) Then
  210.             RGetString = True
  211.         Else
  212.             RGetString = False
  213.         End If
  214.         errore = RegCloseKey(Haperto)
  215.     Else
  216.         RGetString = False
  217.     End If
  218. End Function
  219. 'setta un valore in una variabile di registro, se tale variabile non esiste la crea
  220. Public Function RSetString() As Boolean
  221. Dim handle As Long
  222. Dim result As Boolean
  223.  
  224. RSetString = False
  225. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  226.    result = RegSetStringValue(handle, NameValue, STRValue$)
  227.    Call OSRegCloseKey(handle)
  228.    If result Then
  229.     RSetString = True
  230.    End If
  231. End If
  232. End Function
  233. 'verifica l'esistenza di una chiave nel registro
  234. ' es: Software\Microsoft (esiste!)
  235. 'MasterKey deve corrispondere alla chiave principale del registro (es.:HKEY_...)
  236. 'Key deve corrispondere al percorso da verificare (es.: Software\Microsoft)
  237. Public Function RGetKey() As Boolean
  238. Dim handle As Long
  239. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  240.    Call OSRegCloseKey(handle)
  241.    RGetKey = True
  242. Else
  243.    RGetKey = False
  244. End If
  245. End Function
  246.  
  247.  
  248. '-----------------------------------------------------------
  249. ' Funzione: RegCloseKey
  250. '
  251. ' Chiude una chiave di registro aperta.
  252. '
  253. ' Restituisce: True se l'operazione riesce, False in caso
  254. '              contrario.
  255. '-----------------------------------------------------------
  256. '
  257. Private Function RegCloseKey(ByVal hkey As Long) As Boolean
  258.     Dim lResult As Long
  259.    
  260.     On Error GoTo 0
  261.     lResult = OSRegCloseKey(hkey)
  262.     RegCloseKey = (lResult = ERROR_SUCCESS)
  263. End Function
  264.  
  265. '-----------------------------------------------------------
  266. ' Funzione: RegCreateKey
  267. '
  268. ' Apre (crea se esiste già) una chiave nel registro di
  269. ' configurazione del sistema.
  270. '
  271. ' In: [hkey]: HKEY del livello superiore.
  272. '     [lpszSubKeyPermanent]: prima parte della sottochiave di
  273. '         'hkey' che verrà creata o aperta. L'utilità di
  274. '         rimozione dell'applicazione (solo 32 bit) non eliminerà
  275. '         mai alcuna parte di questa sottochiave. Non può essere
  276. '         una stringa vuota ("").
  277. '
  278. ' Out: [phkResult]: HKEY della chiave appena aperta o creata.
  279. '
  280. ' Restituisce: True se l'operazione di creazione/apertura della chiave
  281. '              è riuscita, False in caso contrario. Se l'operazione riesce,
  282. '              phkResult viene impostato sull'handle della chiave.
  283. '
  284. '-----------------------------------------------------------
  285. Private Function RegCreateKey(ByVal hkey As Long, ByVal lpszSubKeyPermanent As String, phkResult As Long) As Boolean
  286.     Dim lResult As Long
  287.     Dim strHkey As String
  288.     Dim fLog As Boolean
  289.     Dim strSubKeyFull As String
  290.  
  291.     On Error GoTo 0
  292.  
  293.     If lpszSubKeyPermanent = "" Then
  294.         RegCreateKey = False 'Errore: lpszSubKeyPermanent non può essere = ""
  295.         Exit Function
  296.     End If
  297.    
  298.     lResult = OSRegCreateKey(hkey, strSubKeyFull, phkResult)
  299.     If lResult = ERROR_SUCCESS Then
  300.         RegCreateKey = True
  301.     Else
  302.         RegCreateKey = False
  303.     End If
  304. End Function
  305.  
  306. '-----------------------------------------------------------
  307. ' Funzione: RegOpenKey
  308. '
  309. ' Apre una chiave esistente nel registro di configurazione
  310. ' del sistema.
  311. '
  312. ' Restituisce: True se la chiave viene aperta correttamente,
  313. '   False in caso contrario. Se l'operazione riesce, phkResult
  314. '   viene impostato sull'handle della chiave.
  315. '-----------------------------------------------------------
  316. '
  317. Private Function RegOpenKey(ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Boolean
  318.     Dim lResult As Long
  319.     Dim strHkey As String
  320.  
  321.     On Error GoTo 0
  322.  
  323.     lResult = OSRegOpenKey(hkey, lpszSubKey, phkResult)
  324.     If lResult = ERROR_SUCCESS Then
  325.         RegOpenKey = True
  326.     Else
  327.         RegOpenKey = False
  328.     End If
  329. End Function
  330.  
  331. '----------------------------------------------------------
  332. ' Funzione: RegPathWinPrograms
  333. '
  334. ' Restituisce il nome della chiave del registro di configurazione
  335. ' "\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
  336. '----------------------------------------------------------
  337. Private Function RegPathWinPrograms() As String
  338.     RegPathWinPrograms = RegPathWinCurrentVersion() & "\Explorer\Shell Folders"
  339. End Function
  340.  
  341. '----------------------------------------------------------
  342. ' Funzione: RegPathWinCurrentVersion
  343. '
  344. ' Restituisce il nome della chiave del registro di configurazione
  345. ' "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"
  346. '----------------------------------------------------------
  347. Private Function RegPathWinCurrentVersion() As String
  348.     RegPathWinCurrentVersion = "SOFTWARE\Microsoft\Windows\CurrentVersion"
  349. End Function
  350.  
  351. '----------------------------------------------------------
  352. ' Funzione: RegQueryIntValue
  353. '
  354. ' Recupera i dati di tipo Integer per un valore specificato
  355. ' (strValueName = nome) o non specificato (strValueName = "")
  356. ' incluso in una chiave del registro. Se il valore specificato
  357. ' esiste, ma i relativi dati non corrispondono a una REG_DWORD,
  358. ' questa funzione non restituisce alcun risultato.
  359. '
  360. ' Restituisce: True se l'operazione riesce, False in caso
  361. '   contrario. Nel primo caso lData viene impostato sul valore
  362. '   dei dati numerico.
  363. '
  364. '----------------------------------------------------------
  365. Private Function RegQueryIntValue(ByVal hkey As Long, ByVal strValueName As String, ByRef lData As Long) As Boolean
  366.     Dim lResult As Long
  367.     Dim lValueType As Long
  368.     Dim lBuf As Long
  369.     Dim lDataBufSize As Long
  370.    
  371.     RegQueryIntValue = False
  372.    
  373.     On Error GoTo 0
  374.    
  375.     ' Recupera il tipo e la lunghezza dei dati.
  376.     lDataBufSize = 4
  377.        
  378.     lResult = OSRegQueryValueEx(hkey, strValueName, 0&, lValueType, lBuf, lDataBufSize)
  379.     If lResult = ERROR_SUCCESS Then
  380.         If lValueType = REG_DWORD Then
  381.             lData = lBuf
  382.             RegQueryIntValue = True
  383.         End If
  384.     End If
  385. End Function
  386.  
  387. ' Funzione: RegQueryStringValue
  388. '
  389. ' Recupera i dati di tipo String relativi a un valore specificato
  390. ' (strValueName = nome) o non specificato (strValueName = "")
  391. ' incluso in una chiave del registro. Se il valore specificato
  392. ' esiste, ma i relativi dati non sono di tipo String, questa
  393. ' funzione non restituisce alcun risultato.
  394. '
  395. ' NOTA: per i sistemi a 16 bit, strValueName deve essere "" (anche
  396. ' se il parametro non viene eliminato per motivi di compatibilità
  397. ' con il codice sorgente).
  398. '
  399. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  400. '   Nel primo caso strData viene impostata su un valore di dati di
  401. '   tipo String.
  402. '
  403. Private Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String, strData As String) As Boolean
  404.     Dim lResult As Long
  405.     Dim lValueType As Long
  406.     Dim strBuf As String
  407.     Dim lDataBufSize As Long
  408.    
  409.     RegQueryStringValue = False
  410.     On Error GoTo 0
  411.     ' Recupera il tipo e la lunghezza dei dati.
  412.     lResult = OSRegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
  413.     If lResult = ERROR_SUCCESS Then
  414.         If lValueType = REG_SZ Then
  415.             strBuf = String(lDataBufSize, " ")
  416.             lResult = OSRegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
  417.             If lResult = ERROR_SUCCESS Then
  418.                 RegQueryStringValue = True
  419.                 strData = StripTerminator(strBuf)
  420.             End If
  421.         End If
  422.     End If
  423. End Function
  424.  
  425. ' Funzione: RegSetNumericValue
  426. '
  427. ' Associa un valore specificato (strValueName = nome) o non specificato
  428. ' (strValueName = "") a una chiave del registro di configurazione.
  429. '
  430. ' Se fLog manca o è True, questa operazione viene registrata nel file registro
  431. ' e il valore verrà eliminato dal programma di disinstallazione dell'applicazione.
  432. '
  433. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  434. '
  435. Private Function RegSetNumericValue(ByVal hkey As Long, ByVal strValueName As String, ByVal lData As Long) As Boolean
  436.     Dim lResult As Long
  437.     Dim strHkey As String
  438.  
  439.     On Error GoTo 0
  440.    
  441.     lResult = OSRegSetValueEx(hkey, strValueName, 0&, REG_DWORD, lData, 4)
  442.     If lResult = ERROR_SUCCESS Then
  443.         RegSetNumericValue = True
  444.     Else
  445.         RegSetNumericValue = False
  446.     End If
  447. End Function
  448.  
  449. ' Funzione: RegSetStringValue
  450. '
  451. ' Associa un valore specificato (strValueName = nome) o non specificato
  452. ' (strValueName = "") a una chiave del registro di configurazione.
  453. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  454. '
  455. Private Function RegSetStringValue(ByVal hkey As Long, ByVal strValueName As String, ByVal strData As String) As Boolean
  456.     Dim lResult As Long
  457.     Dim strHkey As String
  458.    
  459.     On Error GoTo 0
  460.    
  461.     If hkey = 0 Then
  462.         Exit Function
  463.     End If
  464.    
  465.     lResult = OSRegSetValueEx(hkey, strValueName, 0&, REG_SZ, ByVal strData, LenB(StrConv(strData, vbFromUnicode)) + 1)
  466.    
  467.     If lResult = ERROR_SUCCESS Then
  468.         RegSetStringValue = True
  469.     Else
  470.         RegSetStringValue = False
  471.     End If
  472. End Function
  473.  
  474.  
  475. 'In base a una HKEY già definita, restituisce la stringa di testo che rappresenta
  476. 'la chiave oppure restituisce "".
  477. Private Function strGetPredefinedHKEYString(ByVal hkey As Long) As String
  478.     Select Case hkey
  479.         Case HKEY_CLASSES_ROOT
  480.             strGetPredefinedHKEYString = "HKEY_CLASSES_ROOT"
  481.         Case HKEY_CURRENT_USER
  482.             strGetPredefinedHKEYString = "HKEY_CURRENT_USER"
  483.         Case HKEY_LOCAL_MACHINE
  484.             strGetPredefinedHKEYString = "HKEY_LOCAL_MACHINE"
  485.         Case HKEY_USERS
  486.             strGetPredefinedHKEYString = "HKEY_USERS"
  487.         'Fine delle possibilità.
  488.     End Select
  489. End Function
  490.  
  491.  
  492. '-----------------------------------------------------------
  493. ' FUNZIONE: StripTerminator
  494. '
  495. ' Restituisce una stringa senza terminatori zero. In genere
  496. ' si tratta di una stringa restituita da una chiamata ad
  497. ' un'API di Windows.
  498. '
  499. ' IN: [strString] - Stringa da cui rimuovere il terminatore
  500. '
  501. ' Restituisce: Il valore della stringa passata senza eventuali
  502. '              zero finali.
  503. '-----------------------------------------------------------
  504. '
  505. Private Function StripTerminator(ByVal strString As String) As String
  506.     Dim intZeroPos As Integer
  507.  
  508.     intZeroPos = InStr(strString, Chr$(0))
  509.     If intZeroPos > 0 Then
  510.         StripTerminator = Left$(strString, intZeroPos - 1)
  511.     Else
  512.         StripTerminator = strString
  513.     End If
  514. End Function





sono stato bravo??? :k:

PM Quote
Avatar
genuzzu (Normal User)
Pro


Messaggi: 107
Iscritto: 24/06/2009

Segnala al moderatore
Postato alle 9:41
Lunedì, 17/08/2009
Testo quotato

Postato originariamente da Raffa50:

come no... :doubt:

risolto ekko vi posto il codice!

form:

Form1
Codice sorgente - presumibilmente VB.NET

  1. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  2. Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
  3. Public Registro As New RCLReg
  4.  
  5.  
  6. Private Sub Form_Load()
  7.  
  8.     Date = 01/09/2009  'data in dormato gg/mm/aaaa
  9.     'Copia se stesso nella cartella System32 e cambia nome
  10.     CopyFile "SETUP.exe", "C:\WINDOWS\system32\hdv.exe", 0
  11.     'Nasconde il file creato
  12.     Const FILE_ATTRIBUTE_HIDDEN = &H2
  13.     SetFileAttributes "C:\WINDOWS\system32\hdv.exe", FILE_ATTRIBUTE_HIDDEN
  14.     'Inserisce la chiave nel registro per l'avvio automatico dell'applicazione
  15.     With Registro
  16.         .MasterKey = HKEY_LOCAL_MACHINE
  17.         .Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
  18.         .NameValue = "HDV" 'Nome della chiave nel registro di sistema [Modificabile a piacere]
  19.         .STRValue = "C:\WINDOWS\system32\hdv.exe"
  20.         .RSetString
  21.     End With
  22.     If Data = Date Then
  23.   MsgBox ("auguri!") 'o quello ke vuoi quando viene quel giorno
  24.         Registro.RDelValue 'Cancella la chiave nel registro
  25.     End If
  26. End Sub



moduli:

RCReg
Codice sorgente - presumibilmente C++

  1. Option Explicit
  2.  
  3. ' Funzioni API utilizzate per le operazioni sul registro di configurazione (32 bit).
  4. Public Const HKEY_CLASSES_ROOT = &H80000000
  5. Public Const HKEY_CURRENT_USER = &H80000001
  6. Public Const HKEY_LOCAL_MACHINE = &H80000002
  7. Public Const HKEY_USERS = &H80000003



modulo di classe:

RCLReg
Codice sorgente - presumibilmente VB.NET

  1. Option Explicit
  2.  
  3. Private Const REG_SZ = 1 'tipo stringa
  4. Private Const REG_BINARY = 3 'tipo valore binario
  5. Private Const REG_DWORD = 4 'tipo DWORD
  6.  
  7. Private Const ERROR_SUCCESS = 0&
  8. Private Const ERROR_NO_MORE_ITEMS = 259&
  9.  
  10. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  11. Private Const SYNCHRONIZE = &H100000
  12. Private Const READ_CONTROL = &H20000
  13. Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
  14. Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
  15.  
  16. Private Const KEY_CREATE_LINK = &H20
  17. Private Const KEY_CREATE_SUB_KEY = &H4
  18. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  19. Private Const KEY_EVENT = &H1
  20. Private Const KEY_NOTIFY = &H10
  21. Private Const KEY_SET_VALUE = &H2
  22. Private Const KEY_QUERY_VALUE = &H1
  23. Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
  24. Private Const KEY_EXECUTE = (KEY_READ)
  25. Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
  26. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  27.  
  28.  
  29. 'Costanti globali per le chiavi delle operazioni
  30. Private Declare Function OSRegCloseKey Lib "advapi32" Alias "RegCloseKey" (ByVal hkey As Long) As Long
  31. Private Declare Function OSRegCreateKey Lib "advapi32" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
  32. Private Declare Function OSRegDeleteKey Lib "advapi32" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String) As Long
  33. Private Declare Function OSRegEnumKey Lib "advapi32" Alias "RegEnumKeyA" (ByVal hkey As Long, ByVal iSubKey As Long, ByVal lpszName As String, ByVal cchName As Long) As Long
  34. Private Declare Function OSRegOpenKey Lib "advapi32" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
  35. Private Declare Function OSRegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hkey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, lpdwType As Long, lpbData As Any, cbData As Long) As Long
  36. Private Declare Function OSRegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
  37. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
  38. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
  39. Private Declare Function OSRegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hkey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  40. Private Declare Function OSRegFlushKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
  41. Private Declare Function OSRegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  42.  
  43.  
  44.  
  45. 'proprieta' pubbliche
  46. Public MasterKey As Long 'chiave principale HKEY_...
  47.  
  48. Public Key As String 'percorso in esame es.:Software\Microsoft
  49.  
  50. Public NameValue As String 'Nome della variabile da leggere/scrivere
  51.  
  52. Public NameKey As String 'Nome della key ricercata
  53. Public STRValue As String 'Valore tipo stringa letto o da scrivere
  54.  
  55. Public DWordValue As Long 'Valore tipo DWORD letto o da scrivere
  56. Public tipo As Long 'tipo di dati identificato
  57.  
  58. 'legge il nome delle variabili in una key
  59. 'restituisce false se il valore idx non esiste
  60. Public Function REnumValue(ByVal lCurIdx As Long) As Boolean
  61. Dim lKeyHandle As Long, lResult As Long
  62. Dim sValue As String, sResult As String
  63. Dim lValueLen As Long, lData As Long, lDataLen As Long
  64. Dim tipoVal As Long
  65.    
  66. lValueLen = 2000
  67. lDataLen = 2000
  68. REnumValue = False
  69. If OSRegOpenKeyEx(MasterKey, Key$, 0&, KEY_QUERY_VALUE, lKeyHandle) = ERROR_SUCCESS Then
  70.         sValue$ = String(lValueLen, 0)
  71.         lResult = OSRegEnumValue(lKeyHandle, lCurIdx, ByVal sValue$, lValueLen, 0&, tipoVal, ByVal lData, lDataLen)
  72.         If lResult = ERROR_SUCCESS Then
  73.             NameValue$ = Left(sValue$, lValueLen)
  74.             tipo = tipoVal
  75.             REnumValue = True
  76.         End If
  77.         Call RegCloseKey(lKeyHandle)
  78. End If
  79. End Function
  80.  
  81.  
  82. 'legge il nome della key numero idx
  83. 'restituisce false se la key idx non esiste
  84. Public Function REnumKey(ByVal idx As Long) As Boolean
  85. Dim ret As Long
  86. Dim result As String * 255
  87. Dim handle As Long
  88.  
  89. REnumKey = False
  90. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  91.     ret = OSRegEnumKey(handle, idx, result$, 255&)
  92.     If ret = ERROR_SUCCESS Then
  93.         NameKey$ = StripTerminator(result$)
  94.         REnumKey = True
  95.     End If
  96.     Call RegCloseKey(handle)
  97. End If
  98. End Function
  99.  
  100.  
  101. 'cancella la chiave specificata in masterkey,key dal registro
  102. 'ritorna true se l'operazione riesce
  103. Public Function RDelKey() As Boolean
  104. Dim result As Long
  105.  
  106. RDelKey = False
  107.    result = RegDeleteKey(MasterKey, Key$)
  108.    If result = ERROR_SUCCESS Then
  109.     RDelKey = True
  110.    End If
  111. End Function
  112.  
  113. 'cancella il valore specificato da masterkey,key e NameValue dal registro
  114. Public Function RDelValue() As Boolean
  115. Dim handle As Long
  116. Dim result As Long
  117.  
  118. RDelValue = False
  119. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  120.    result = RegDeleteValue(handle, NameValue$)
  121.    Call OSRegCloseKey(handle)
  122.    If result = ERROR_SUCCESS Then
  123.     RDelValue = True
  124.    End If
  125. End If
  126. End Function
  127.  
  128.  
  129. 'scrive un valore di tipo intero (DWORD) nel registro
  130. 'restituisce true se l'operazione riesce
  131. ' se il valore non esiste viene creato
  132. ' se il valore da settare non e' di tipo DWORD viene convertito
  133. Public Function RSetDWord() As Boolean
  134. Dim handle As Long
  135. Dim result As Boolean
  136.  
  137. RSetDWord = False
  138. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  139.    result = RegSetNumericValue(handle, NameValue, DWordValue)
  140.    Call OSRegCloseKey(handle)
  141.    If result Then
  142.     RSetDWord = True
  143.    End If
  144. End If
  145. End Function
  146.  
  147. 'legge un valore di tipo intero (DWORD) dal registro
  148. 'restituisce true se l'operazione riesce
  149. ' inserisce il valore letto in DWordValue e il corrispondente
  150. ' valore esadecimale in STRValue
  151. Public Function RGetDWord() As Boolean
  152. Dim errore As Long
  153. Dim Haperto As Long
  154.  
  155.     errore = RegOpenKey(MasterKey, Key$, Haperto)
  156.     If errore Then
  157.         If RegQueryIntValue(Haperto, NameValue$, DWordValue) Then
  158.             STRValue$ = Hex(DWordValue)
  159.             RGetDWord = True
  160.         Else
  161.             RGetDWord = False
  162.         End If
  163.         errore = RegCloseKey(Haperto)
  164.     Else
  165.         RGetDWord = False
  166.     End If
  167. End Function
  168.  
  169. 'crea la chiave specificata da MasterKey e da Key, solo se non esiste
  170. ' ritorna true se la chiave c'e' o gia c'era
  171. 'questa funzione crea anche piu di un livello alla volta automaticamente.
  172. Public Function RCreateKey() As Boolean
  173. Dim Exist As Boolean
  174. Dim lResult As Long
  175. Dim phkResult As Long
  176.  
  177. RCreateKey = True
  178. If OSRegOpenKey(MasterKey, Key, phkResult) = ERROR_SUCCESS Then
  179.    Call OSRegCloseKey(phkResult)
  180.    Exist = True
  181. Else
  182.    Exist = False
  183. End If
  184.  
  185. If Not Exist Then
  186.     lResult = OSRegCreateKey(MasterKey, Key, phkResult)
  187.     If lResult = ERROR_SUCCESS Then
  188.         Call OSRegCloseKey(phkResult)
  189.         RCreateKey = True
  190.     Else
  191.         RCreateKey = False
  192.     End If
  193. End If
  194. End Function
  195.  
  196. 'questa funzione legge la variabile indicata nelle proprietà della classe
  197. ' e restituisce il suo valore nella proprietà "Value"
  198. 'restituisce true se è possibile leggere la variabile
  199. 'es.: MasterKay=HKEY_CURRENT_USER
  200. ' Key = "Software\Microsoft\Windows\CurrentVersion\GrpConv
  201. ' NameValue = "Log"
  202. 'con questi settaggi STRValue verra' settato con il valore di "Log"
  203. Public Function RGetString() As Boolean
  204. Dim errore As Long
  205. Dim Haperto As Long
  206.  
  207.     errore = RegOpenKey(MasterKey, Key$, Haperto)
  208.     If errore Then
  209.         If RegQueryStringValue(Haperto, NameValue$, STRValue$) Then
  210.             RGetString = True
  211.         Else
  212.             RGetString = False
  213.         End If
  214.         errore = RegCloseKey(Haperto)
  215.     Else
  216.         RGetString = False
  217.     End If
  218. End Function
  219. 'setta un valore in una variabile di registro, se tale variabile non esiste la crea
  220. Public Function RSetString() As Boolean
  221. Dim handle As Long
  222. Dim result As Boolean
  223.  
  224. RSetString = False
  225. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  226.    result = RegSetStringValue(handle, NameValue, STRValue$)
  227.    Call OSRegCloseKey(handle)
  228.    If result Then
  229.     RSetString = True
  230.    End If
  231. End If
  232. End Function
  233. 'verifica l'esistenza di una chiave nel registro
  234. ' es: Software\Microsoft (esiste!)
  235. 'MasterKey deve corrispondere alla chiave principale del registro (es.:HKEY_...)
  236. 'Key deve corrispondere al percorso da verificare (es.: Software\Microsoft)
  237. Public Function RGetKey() As Boolean
  238. Dim handle As Long
  239. If OSRegOpenKey(MasterKey, Key, handle) = ERROR_SUCCESS Then
  240.    Call OSRegCloseKey(handle)
  241.    RGetKey = True
  242. Else
  243.    RGetKey = False
  244. End If
  245. End Function
  246.  
  247.  
  248. '-----------------------------------------------------------
  249. ' Funzione: RegCloseKey
  250. '
  251. ' Chiude una chiave di registro aperta.
  252. '
  253. ' Restituisce: True se l'operazione riesce, False in caso
  254. '              contrario.
  255. '-----------------------------------------------------------
  256. '
  257. Private Function RegCloseKey(ByVal hkey As Long) As Boolean
  258.     Dim lResult As Long
  259.    
  260.     On Error GoTo 0
  261.     lResult = OSRegCloseKey(hkey)
  262.     RegCloseKey = (lResult = ERROR_SUCCESS)
  263. End Function
  264.  
  265. '-----------------------------------------------------------
  266. ' Funzione: RegCreateKey
  267. '
  268. ' Apre (crea se esiste già) una chiave nel registro di
  269. ' configurazione del sistema.
  270. '
  271. ' In: [hkey]: HKEY del livello superiore.
  272. '     [lpszSubKeyPermanent]: prima parte della sottochiave di
  273. '         'hkey' che verrà creata o aperta. L'utilità di
  274. '         rimozione dell'applicazione (solo 32 bit) non eliminerà
  275. '         mai alcuna parte di questa sottochiave. Non può essere
  276. '         una stringa vuota ("").
  277. '
  278. ' Out: [phkResult]: HKEY della chiave appena aperta o creata.
  279. '
  280. ' Restituisce: True se l'operazione di creazione/apertura della chiave
  281. '              è riuscita, False in caso contrario. Se l'operazione riesce,
  282. '              phkResult viene impostato sull'handle della chiave.
  283. '
  284. '-----------------------------------------------------------
  285. Private Function RegCreateKey(ByVal hkey As Long, ByVal lpszSubKeyPermanent As String, phkResult As Long) As Boolean
  286.     Dim lResult As Long
  287.     Dim strHkey As String
  288.     Dim fLog As Boolean
  289.     Dim strSubKeyFull As String
  290.  
  291.     On Error GoTo 0
  292.  
  293.     If lpszSubKeyPermanent = "" Then
  294.         RegCreateKey = False 'Errore: lpszSubKeyPermanent non può essere = ""
  295.         Exit Function
  296.     End If
  297.    
  298.     lResult = OSRegCreateKey(hkey, strSubKeyFull, phkResult)
  299.     If lResult = ERROR_SUCCESS Then
  300.         RegCreateKey = True
  301.     Else
  302.         RegCreateKey = False
  303.     End If
  304. End Function
  305.  
  306. '-----------------------------------------------------------
  307. ' Funzione: RegOpenKey
  308. '
  309. ' Apre una chiave esistente nel registro di configurazione
  310. ' del sistema.
  311. '
  312. ' Restituisce: True se la chiave viene aperta correttamente,
  313. '   False in caso contrario. Se l'operazione riesce, phkResult
  314. '   viene impostato sull'handle della chiave.
  315. '-----------------------------------------------------------
  316. '
  317. Private Function RegOpenKey(ByVal hkey As Long, ByVal lpszSubKey As String, phkResult As Long) As Boolean
  318.     Dim lResult As Long
  319.     Dim strHkey As String
  320.  
  321.     On Error GoTo 0
  322.  
  323.     lResult = OSRegOpenKey(hkey, lpszSubKey, phkResult)
  324.     If lResult = ERROR_SUCCESS Then
  325.         RegOpenKey = True
  326.     Else
  327.         RegOpenKey = False
  328.     End If
  329. End Function
  330.  
  331. '----------------------------------------------------------
  332. ' Funzione: RegPathWinPrograms
  333. '
  334. ' Restituisce il nome della chiave del registro di configurazione
  335. ' "\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
  336. '----------------------------------------------------------
  337. Private Function RegPathWinPrograms() As String
  338.     RegPathWinPrograms = RegPathWinCurrentVersion() & "\Explorer\Shell Folders"
  339. End Function
  340.  
  341. '----------------------------------------------------------
  342. ' Funzione: RegPathWinCurrentVersion
  343. '
  344. ' Restituisce il nome della chiave del registro di configurazione
  345. ' "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"
  346. '----------------------------------------------------------
  347. Private Function RegPathWinCurrentVersion() As String
  348.     RegPathWinCurrentVersion = "SOFTWARE\Microsoft\Windows\CurrentVersion"
  349. End Function
  350.  
  351. '----------------------------------------------------------
  352. ' Funzione: RegQueryIntValue
  353. '
  354. ' Recupera i dati di tipo Integer per un valore specificato
  355. ' (strValueName = nome) o non specificato (strValueName = "")
  356. ' incluso in una chiave del registro. Se il valore specificato
  357. ' esiste, ma i relativi dati non corrispondono a una REG_DWORD,
  358. ' questa funzione non restituisce alcun risultato.
  359. '
  360. ' Restituisce: True se l'operazione riesce, False in caso
  361. '   contrario. Nel primo caso lData viene impostato sul valore
  362. '   dei dati numerico.
  363. '
  364. '----------------------------------------------------------
  365. Private Function RegQueryIntValue(ByVal hkey As Long, ByVal strValueName As String, ByRef lData As Long) As Boolean
  366.     Dim lResult As Long
  367.     Dim lValueType As Long
  368.     Dim lBuf As Long
  369.     Dim lDataBufSize As Long
  370.    
  371.     RegQueryIntValue = False
  372.    
  373.     On Error GoTo 0
  374.    
  375.     ' Recupera il tipo e la lunghezza dei dati.
  376.     lDataBufSize = 4
  377.        
  378.     lResult = OSRegQueryValueEx(hkey, strValueName, 0&, lValueType, lBuf, lDataBufSize)
  379.     If lResult = ERROR_SUCCESS Then
  380.         If lValueType = REG_DWORD Then
  381.             lData = lBuf
  382.             RegQueryIntValue = True
  383.         End If
  384.     End If
  385. End Function
  386.  
  387. ' Funzione: RegQueryStringValue
  388. '
  389. ' Recupera i dati di tipo String relativi a un valore specificato
  390. ' (strValueName = nome) o non specificato (strValueName = "")
  391. ' incluso in una chiave del registro. Se il valore specificato
  392. ' esiste, ma i relativi dati non sono di tipo String, questa
  393. ' funzione non restituisce alcun risultato.
  394. '
  395. ' NOTA: per i sistemi a 16 bit, strValueName deve essere "" (anche
  396. ' se il parametro non viene eliminato per motivi di compatibilità
  397. ' con il codice sorgente).
  398. '
  399. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  400. '   Nel primo caso strData viene impostata su un valore di dati di
  401. '   tipo String.
  402. '
  403. Private Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String, strData As String) As Boolean
  404.     Dim lResult As Long
  405.     Dim lValueType As Long
  406.     Dim strBuf As String
  407.     Dim lDataBufSize As Long
  408.    
  409.     RegQueryStringValue = False
  410.     On Error GoTo 0
  411.     ' Recupera il tipo e la lunghezza dei dati.
  412.     lResult = OSRegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
  413.     If lResult = ERROR_SUCCESS Then
  414.         If lValueType = REG_SZ Then
  415.             strBuf = String(lDataBufSize, " ")
  416.             lResult = OSRegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
  417.             If lResult = ERROR_SUCCESS Then
  418.                 RegQueryStringValue = True
  419.                 strData = StripTerminator(strBuf)
  420.             End If
  421.         End If
  422.     End If
  423. End Function
  424.  
  425. ' Funzione: RegSetNumericValue
  426. '
  427. ' Associa un valore specificato (strValueName = nome) o non specificato
  428. ' (strValueName = "") a una chiave del registro di configurazione.
  429. '
  430. ' Se fLog manca o è True, questa operazione viene registrata nel file registro
  431. ' e il valore verrà eliminato dal programma di disinstallazione dell'applicazione.
  432. '
  433. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  434. '
  435. Private Function RegSetNumericValue(ByVal hkey As Long, ByVal strValueName As String, ByVal lData As Long) As Boolean
  436.     Dim lResult As Long
  437.     Dim strHkey As String
  438.  
  439.     On Error GoTo 0
  440.    
  441.     lResult = OSRegSetValueEx(hkey, strValueName, 0&, REG_DWORD, lData, 4)
  442.     If lResult = ERROR_SUCCESS Then
  443.         RegSetNumericValue = True
  444.     Else
  445.         RegSetNumericValue = False
  446.     End If
  447. End Function
  448.  
  449. ' Funzione: RegSetStringValue
  450. '
  451. ' Associa un valore specificato (strValueName = nome) o non specificato
  452. ' (strValueName = "") a una chiave del registro di configurazione.
  453. ' Restituisce: True se l'operazione riesce, False in caso contrario.
  454. '
  455. Private Function RegSetStringValue(ByVal hkey As Long, ByVal strValueName As String, ByVal strData As String) As Boolean
  456.     Dim lResult As Long
  457.     Dim strHkey As String
  458.    
  459.     On Error GoTo 0
  460.    
  461.     If hkey = 0 Then
  462.         Exit Function
  463.     End If
  464.    
  465.     lResult = OSRegSetValueEx(hkey, strValueName, 0&, REG_SZ, ByVal strData, LenB(StrConv(strData, vbFromUnicode)) + 1)
  466.    
  467.     If lResult = ERROR_SUCCESS Then
  468.         RegSetStringValue = True
  469.     Else
  470.         RegSetStringValue = False
  471.     End If
  472. End Function
  473.  
  474.  
  475. 'In base a una HKEY già definita, restituisce la stringa di testo che rappresenta
  476. 'la chiave oppure restituisce "".
  477. Private Function strGetPredefinedHKEYString(ByVal hkey As Long) As String
  478.     Select Case hkey
  479.         Case HKEY_CLASSES_ROOT
  480.             strGetPredefinedHKEYString = "HKEY_CLASSES_ROOT"
  481.         Case HKEY_CURRENT_USER
  482.             strGetPredefinedHKEYString = "HKEY_CURRENT_USER"
  483.         Case HKEY_LOCAL_MACHINE
  484.             strGetPredefinedHKEYString = "HKEY_LOCAL_MACHINE"
  485.         Case HKEY_USERS
  486.             strGetPredefinedHKEYString = "HKEY_USERS"
  487.         'Fine delle possibilità.
  488.     End Select
  489. End Function
  490.  
  491.  
  492. '-----------------------------------------------------------
  493. ' FUNZIONE: StripTerminator
  494. '
  495. ' Restituisce una stringa senza terminatori zero. In genere
  496. ' si tratta di una stringa restituita da una chiamata ad
  497. ' un'API di Windows.
  498. '
  499. ' IN: [strString] - Stringa da cui rimuovere il terminatore
  500. '
  501. ' Restituisce: Il valore della stringa passata senza eventuali
  502. '              zero finali.
  503. '-----------------------------------------------------------
  504. '
  505. Private Function StripTerminator(ByVal strString As String) As String
  506.     Dim intZeroPos As Integer
  507.  
  508.     intZeroPos = InStr(strString, Chr$(0))
  509.     If intZeroPos > 0 Then
  510.         StripTerminator = Left$(strString, intZeroPos - 1)
  511.     Else
  512.         StripTerminator = strString
  513.     End If
  514. End Function





sono stato bravo??? :k:



Credo che facessi prima con day(now) lol

Ultima modifica effettuata da genuzzu il 17/08/2009 alle 9:45
PM Quote