利用硬盘序列号计算软件注册码

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 sth1002 的 blog

利用硬盘序列号计算软件注册码。

在模块中加入下列声明:
public declare function getvolumeinformation lib "kernel32" _
  alias "getvolumeinformationa" (byval lprootpathname as string, _
  byval lpvolumenamebuffer as string, byval nvolumenamesize as long, _
  lpvolumeserialnumber as long, lpmaximumcomponentlength as long, _
  lpfilesystemflags as long, byval lpfilesystemnamebuffer as string, _
  byval nfilesystemnamesize as long) as long
'得到某一磁盘分区的信息,如c:

窗体代码如下:
option explicit
private regid, localid as long

private sub cmdlocalid_click()
  '根据c盘序列号得到原id
  dim driver, volname, fsys as string
  dim volnumber, mcm, fsf as long
  driver = "c:\"
  dim res as long
  res = getvolumeinformation(driver, volname, 127, volnumber, mcm, fsf, fsys, 127)
  'volnumber是c盘序列号
  localid = volnumber / 2 + 123456789
  text1.text = localid
end sub

private sub cmdregid_click()
  '根据原id算出注册id
  if isnumeric(text1.text) then
    regid = clng(text1.text) / 4 * 3 + 987654321
  else
    'error
  end if
  text2.text = regid
end sub

private sub cmndcheckid_click()
  '验证注册id
  dim driver, volname, fsys as string
  dim volnumber, mcm, fsf as long
  driver = "c:\"
  dim res as long
  res = getvolumeinformation(driver, volname, 127, volnumber, mcm, fsf, fsys, 127)
  dim tid as long
  tid = volnumber / 2 + 123456789
  if regid = tid / 4 * 3 + 987654321 then
    msgbox "正确!"
  else
    msgbox "错误!"
  end if
end sub

为便于演示,我在窗体上用了两个文本框三个按钮,请根据情况灵活使用,可以在用户端算出原id,发给你,你算出注册id再发给用户,验证当然是在用户端啦。id算法很简单,只作示范。此注册id只能在这一台机器上使用,对于非高手用户来说是足够啦。
注:如用户格式化c:盘后需重新获得id。

本文关键:硬盘序列号、注册码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top