[VBA] (Registery) Kayıt Defteri kullanımı için WScript mi API mi sağlıklıdır?
#1
Merhaba,

Bir accdb yi başlatırken registery kayıtları okumam ve yazmam gerekiyor. Fakat bu iş için API ve WScript kodları oalrak iki yöntem gördüm. Aslında kayıt okuma sorunu olmasa Regedit.exe ile en sağlam şekilde oluyor ama iş değişik biraz.

ekte API ile, aşağıda WScript ile olan kodlar var. Tecrüblerinizi öğrenemk isityorum. Hangisin windows ve access sürümüne diline göre daha az sorun çıkar. Referans vb yönleri de katarsak bağ ağrıtmayacak olan hangisidir?(ağrıtsa da az ağrıtsın)?

Bir süredir kullanıp da memnun kaldığınız kodlar var mıdır?


Visual Basic
  1. 'reads the value for the registry key i_RegKey
  2. 'if the key cannot be found, the return value is ""
  3. Function RegKeyRead(i_RegKey As String) As String
  4. Dim myWS As Object
  5.  
  6. On Error Resume Next
  7. 'access Windows scripting
  8. Set myWS = CreateObject("WScript.Shell")
  9. 'read key from registry
  10. RegKeyRead = myWS.RegRead(i_RegKey)
  11. End Function
  12.  
  13.  
  14. Checking if a Registry key exists:
  15.  
  16. 'returns True if the registry key i_RegKey was found
  17. 'and False if not
  18. Function RegKeyExists(i_RegKey As String) As Boolean
  19. Dim myWS As Object
  20.  
  21. On Error GoTo ErrorHandler
  22. 'access Windows scripting
  23. Set myWS = CreateObject("WScript.Shell")
  24. 'try to read the registry key
  25. myWS.RegRead i_RegKey
  26. 'key was found
  27. RegKeyExists = True
  28. Exit Function
  29.  
  30. ErrorHandler:
  31. 'key was not found
  32. RegKeyExists = False
  33. End Function
  34.  
  35.  
  36. Saving a Registry key:
  37.  
  38. 'sets the registry key i_RegKey to the
  39. 'value i_Value with type i_Type
  40. 'if i_Type is omitted, the value will be saved as string
  41. 'if i_RegKey wasn't found, a new registry key will be created
  42. Sub RegKeySave(i_RegKey As String, _
  43. i_Value As String, _
  44. Optional i_Type As String = "REG_SZ")
  45. Dim myWS As Object
  46.  
  47. 'access Windows scripting
  48. Set myWS = CreateObject("WScript.Shell")
  49. 'write registry key
  50. myWS.RegWrite i_RegKey, i_Value, i_Type
  51.  
  52. End Sub
  53.  
  54.  
  55. Deleting a key from the Registry:
  56.  
  57. 'deletes i_RegKey from the registry
  58. 'returns True if the deletion was successful,
  59. 'and False if not (the key couldn't be found)
  60. Function RegKeyDelete(i_RegKey As String) As Boolean
  61. Dim myWS As Object
  62.  
  63. On Error GoTo ErrorHandler
  64. 'access Windows scripting
  65. Set myWS = CreateObject("WScript.Shell")
  66. 'delete registry key
  67. myWS.RegDelete i_RegKey
  68. 'deletion was successful
  69. RegKeyDelete = True
  70. Exit Function
  71.  
  72. ErrorHandler:
  73. 'deletion wasn't successful
  74. RegKeyDelete = False
  75. End Function



Visual Basic
  1. Sub TestRegistry()
  2. Dim myRegKey As String
  3. Dim myValue As String
  4. Dim myAnswer As Integer
  5.  
  6. 'get registry key to work with
  7. myRegKey = InputBox("Which registry key do you want to read?", _
  8. "Get Registry Key")
  9. If myRegKey = "" Then Exit Sub
  10. 'check if key exists
  11. If RegKeyExists(myRegKey) = True Then
  12. 'key exists, read it
  13. myValue = RegKeyRead(myRegKey)
  14. 'display result and ask if it should be changed
  15. myAnswer = MsgBox("The registry value for the key """ & _
  16. myRegKey & """" & vbCr & "is """ & myValue & _
  17. """" & vbCr & vbCr & _
  18. "Do you want to change it?", vbYesNo)
  19. Else
  20. 'key doesn't exist, ask if it should be created
  21. myAnswer = MsgBox("The registry key """ & myRegKey & _
  22. """ could not be found." & vbCr & vbCr & _
  23. "Do you want to create it?", vbYesNo)
  24. End If
  25. If myAnswer = vbYes Then
  26. 'ask for new registry key value
  27. myValue = InputBox("Please enter new value:", _
  28. myRegKey, myValue)
  29. If myValue <> "" Then
  30. 'save/create registry key with new value
  31. RegKeySave myRegKey, myValue
  32. MsgBox "Registry key saved."
  33. End If
  34. End If
  35.  
  36. 'ask if key should be deleted from registry
  37. myAnswer = MsgBox("Do you want to delete the registry key """ & _
  38. myRegKey & """?", vbYesNo)
  39. If myAnswer = vbYes Then
  40. 'delete registry key
  41. If RegKeyDelete(myRegKey) = True Then
  42. 'deletion was successful
  43. MsgBox "Registry key """ & myRegKey & """ deleted."
  44. Else
  45. 'deletion wasn't successful
  46. MsgBox "Registry key """ & myRegKey & _
  47. """ could not be deleted."
  48. End If
  49. End If
  50. End Sub




Eklenti Dosyaları
.zip   ColorSchemeV1.3.zip (Boyut: 34,12 KB / İndirilme: 82)
Eek VT:Veri Tabanı, AVT: Access VT, MS:Microsoft, Kapaç: Kapa ve aç (rebot ve açkapa saçmalığına çözümüm)
Twitcy Yazan okuyan sağolsun, çözene saygılar. Kolaylaştırınız, zorlaştırmayınız.
? Cinnet geçirmemek için Access 2010'u SP2 ile kullanalım.
? Sürekli sebepsiz hatalar oluyor da AVT uçuyorsa siz de Ofis kurulmunu uçurun çözülüyor. Sorun kurulum dosyanızda! Farklısını bulun!
? VT dağıtıma çıkana kadar bölmek zaman kaybıdır!
{ Veri Tabanı Mantığı } {Access 2010 çökmelerine çözüm } { 60 Günlük Ofis 2010 Pro Türkçe } { Kayıtları Yan Yana Göstermek }
{ Forma Rapora Resim Fotoğraf Eklemek En kolay En Sağlam En Zengin Teknik }



  Alıntı
Bu mesajı beğenenler:


Benzer Konular...
Konu: Yazar Cevaplar: Gösterim: Son Mesaj
  Dsum Ve Dcount Fonksiyonlarının Birlikte Kullanımı evren89 1 581 16-05-2024, 10:37
Son Mesaj: dsezgin
  Dcount Kullanımı. Satir 22 2.415 15-03-2024, 17:09
Son Mesaj: Satir
  Access Projesi Için Onedrive Kullanımı ccollezium 2 637 14-02-2024, 16:53
Son Mesaj: ccollezium
  [SORGU] ııf Ve ıs Not Null Birlkite Kullanımı Samih KARSLI 11 1.607 05-12-2023, 12:14
Son Mesaj: halily
  Autoexec Kullanımı ates2014 8 1.125 12-11-2023, 17:42
Son Mesaj: BeyTor
  [VBA] Kayıt Iptali: Kayıt Iptal Tablosuna Ekle, Kayıdı Sil Işlemi programmer67 6 1.550 21-07-2023, 10:40
Son Mesaj: onur_can
  Sql Satırında Değişken Kullanımı Hakkında Yardım programmer67 3 751 26-04-2023, 12:02
Son Mesaj: halily
  Toplu Taksitlendirme Işleminde Her Taksit Için Tabloya Ayrı Kayıt Nasıl Yapabilirim. OĞUZ TÜRKYILMAZ 10 1.722 12-03-2023, 21:18
Son Mesaj: OĞUZ TÜRKYILMAZ

Foruma Git:


Bu konuyu görüntüleyen kullanıcı(lar): 1 Ziyaretçi