’bu demo surum ornegi kullanim sayisina goredir.
’tabi ki cok basir bir program olup mantigin anlasilamsi icin iyi bir ornek.
<b>’Form</b>
Option Explicit
Private Const DemoKullanimIzni% = 10
Private KullanimSayisi%, Lisans$
<b>Private Sub Form_Initialize()</b>
’lisansi oku
Lisans = rReadRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "Lisans")
’Lisans gecerli mi
’Burada kendi lisans kontrol eden programini yaz
If Lisans <> "Ramci" Then
’kullanim sayisini oku
KullanimSayisi = Val(rReadRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "KullanimSayisi"))
’kullanimsayisini bir arttir
KullanimSayisi = KullanimSayisi + 1
Debug.Print KullanimSayisi
’tekrar keydet
Call rWriteRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "KullanimSayisi", CStr(KullanimSayisi))
’ilk kullanim mi?
If KullanimSayisi = 1 Then
’Program ilk defa calistirildi
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Call MsgBox("Programi demo olarak ilk defa calistirdiniz" + vbNewLine + "Umarim bizden memnun kalirsiniz...", vbInformation, "Demo")
ElseIf CInt(KullanimSayisi) <= DemoKullanimIzni Then
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Call MsgBox("Programi " + CStr(KullanimSayisi) + ". kez calistirdiniz..." + vbNewLine + "Kalan demo kullanim sayisi " + CStr(DemoKullanimIzni - KullanimSayisi), vbInformation, "Demo")
Else
’Demo surum sona erdi
’lisans iste
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Lisans = InputBox("Demo kullanim izni tukendi" + vbNewLine + "Lutfen lisans giriniz...", "Demo")
’hic bir sey girilmediyse cik
If Lisans = "" Then End
’girilen lisans gecerli m?
If Lisans <> "Ramci" Then
’gecerlisiz lisans
Call MsgBox("Girmis oldugunuz " + Lisans + " lisansi gecerli degil!", vbCritical, "Demo")
End
Else
’basliktaki DEMO yazisini kaldir
Caption = Left(Caption, Len(Caption) - Len(" DEMO"))
’gecerli lisans
Call MsgBox("Programi lisansladiginiz icin tesekkur ederiz", vbInformation, "Tam Surum")
’lisansi kaydet
Call rWriteRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "Lisans", Lisans)
End If
End If
Else
’Program Lisansli
End If
<b>End Sub</b>
<b>’Modul</b>
Option Explicit
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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ& = 1
Public Function rReadRegSZ$(hKey&, lpSubKey$, lpValueName$)
Dim nBuffer&
rReadRegSZ = String(256, Chr(0))
Call RegOpenKey(hKey, lpSubKey, nBuffer)
Call RegQueryValueEx(nBuffer, lpValueName, 0, REG_SZ, ByVal rReadRegSZ, Len(rReadRegSZ))
Call RegCloseKey(nBuffer)
nBuffer = InStr(1, rReadRegSZ, Chr(0)) - 1
rReadRegSZ = IIf(nBuffer = 0, "", Left$(rReadRegSZ, nBuffer))
End Function
Public Sub rWriteRegSZ(hKey&, lpSubKey$, lpValueName$, lpValue$)
Dim nBuffer&
Call RegCreateKey(hKey, lpSubKey, nBuffer)
Call RegSetValueEx(nBuffer, lpValueName, 0, REG_SZ, ByVal lpValue, Len(lpValue))
Call RegCloseKey(nBuffer)
End Sub
İşte programınızı demo yapmak için gerekli kodlar ..
Selametle..
’tabi ki cok basir bir program olup mantigin anlasilamsi icin iyi bir ornek.
<b>’Form</b>
Option Explicit
Private Const DemoKullanimIzni% = 10
Private KullanimSayisi%, Lisans$
<b>Private Sub Form_Initialize()</b>
’lisansi oku
Lisans = rReadRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "Lisans")
’Lisans gecerli mi
’Burada kendi lisans kontrol eden programini yaz
If Lisans <> "Ramci" Then
’kullanim sayisini oku
KullanimSayisi = Val(rReadRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "KullanimSayisi"))
’kullanimsayisini bir arttir
KullanimSayisi = KullanimSayisi + 1
Debug.Print KullanimSayisi
’tekrar keydet
Call rWriteRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "KullanimSayisi", CStr(KullanimSayisi))
’ilk kullanim mi?
If KullanimSayisi = 1 Then
’Program ilk defa calistirildi
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Call MsgBox("Programi demo olarak ilk defa calistirdiniz" + vbNewLine + "Umarim bizden memnun kalirsiniz...", vbInformation, "Demo")
ElseIf CInt(KullanimSayisi) <= DemoKullanimIzni Then
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Call MsgBox("Programi " + CStr(KullanimSayisi) + ". kez calistirdiniz..." + vbNewLine + "Kalan demo kullanim sayisi " + CStr(DemoKullanimIzni - KullanimSayisi), vbInformation, "Demo")
Else
’Demo surum sona erdi
’lisans iste
’Basliga DEMO ekle
Caption = Caption + " DEMO"
Lisans = InputBox("Demo kullanim izni tukendi" + vbNewLine + "Lutfen lisans giriniz...", "Demo")
’hic bir sey girilmediyse cik
If Lisans = "" Then End
’girilen lisans gecerli m?
If Lisans <> "Ramci" Then
’gecerlisiz lisans
Call MsgBox("Girmis oldugunuz " + Lisans + " lisansi gecerli degil!", vbCritical, "Demo")
End
Else
’basliktaki DEMO yazisini kaldir
Caption = Left(Caption, Len(Caption) - Len(" DEMO"))
’gecerli lisans
Call MsgBox("Programi lisansladiginiz icin tesekkur ederiz", vbInformation, "Tam Surum")
’lisansi kaydet
Call rWriteRegSZ(HKEY_LOCAL_MACHINE, "Software/" + App.EXEName, "Lisans", Lisans)
End If
End If
Else
’Program Lisansli
End If
<b>End Sub</b>
<b>’Modul</b>
Option Explicit
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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ& = 1
Public Function rReadRegSZ$(hKey&, lpSubKey$, lpValueName$)
Dim nBuffer&
rReadRegSZ = String(256, Chr(0))
Call RegOpenKey(hKey, lpSubKey, nBuffer)
Call RegQueryValueEx(nBuffer, lpValueName, 0, REG_SZ, ByVal rReadRegSZ, Len(rReadRegSZ))
Call RegCloseKey(nBuffer)
nBuffer = InStr(1, rReadRegSZ, Chr(0)) - 1
rReadRegSZ = IIf(nBuffer = 0, "", Left$(rReadRegSZ, nBuffer))
End Function
Public Sub rWriteRegSZ(hKey&, lpSubKey$, lpValueName$, lpValue$)
Dim nBuffer&
Call RegCreateKey(hKey, lpSubKey, nBuffer)
Call RegSetValueEx(nBuffer, lpValueName, 0, REG_SZ, ByVal lpValue, Len(lpValue))
Call RegCloseKey(nBuffer)
End Sub
İşte programınızı demo yapmak için gerekli kodlar ..
Selametle..