年份后删除注册表Vb网

问题描述:

我怎样才能让我的执照工作只有一年?当我激活我的程序时,我使用当前日期添加注册表。在每次运行中,我检查注册表是否存在。如果注册表存在,我可以使用我的应用程序,否则它会提示我激活它。年份后删除注册表Vb网

我想让我的执照只工作一年。

我试着用

Public Sub Licence_Check() 


    Dim licenca As Date 
      Dim days As Integer 
      licenca = CDate(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\tFull", "tFull", Nothing)) 
     days = CInt(365 - (DateDiff(DateInterval.Day, licenca, Now))) 

     If days <= 0 Then 
      My.Computer.Registry.CurrentUser.DeleteValue("tFull") 
      pbInfo.Value = pbInfo.Maximum 
      gpbInfo.Text = "One year Licence OVER" 
      RbContinue.Enabled = False 
     End If 
End Sub 
+1

您是否意识到这种方法的弱点?使用进程监视器来发现程序存储这些信息的位置并篡改它是一件很重要的事情。 – Steve 2014-10-17 10:29:13

+0

@Steve此程序将使用计算机begginers,因此它不需要高度保护 – Anel 2014-10-17 10:30:35

我已经警告过你关于这种方法的弱点,但是这是你怎么能写上License_Check

,你应该存储应用程序
Public Sub Licence_Check() 
    Dim licenca As Date 
    Using tempKey = My.Computer.Registry.CurrentUser.OpenSubKey("Software\YourAppNameHere", true) 
     licenca = CDate(tempKey.GetValue("InstallDate", Nothing)) 
     Dim limit = licenca.AddYears(1) 
     if limit < DateTime.Today 
      tempKey.DeleteValue("InstallDate") 
      Console.WriteLine ("One year Licence OVER") 
     End If 
    End Using 
End Sub 

公告信息在SOFTWARE子项的子项中,而不是直接在根目录HKEY_CURRENT_USER下。然后你需要打开相应的子键来请求写权限,最后读取需要的值。

要查看日期,只需在读取的值上添加1年,然后按照“今日”进行检查。 要删除您应该使用打开的子项的DeleteValue方法。

另外我想这不是一个检查,应该由用户基础应用于用户。相反,它是一个可以应用于整个应用程序的检查。在这种情况下,您应该使用预定义的My.Computer.Registry.LocalMachine注册表项。