怎么样通过ASP编程获得硬盘序列号?
PrivateDeclareFunctionGetVolumeInformation&Lib"kernel32"Alias"GetVolumeInformationA"(ByVallpRootPathNameAsString,ByValpVolumeNameBufferAsString,ByValnVolumeNameSizeAsLong,lpVolumeSerialNumberAsLong,lpMaximumComponentLengthAsLong,lpFileSystemFlagsAsLong,ByVallpFileSystemNameBufferAsString,ByValnFileSystemNameSizeAsLong)
PrivateConstMAX_FILENAME_LEN=256
PrivateConstGETSERIALPASSWORD="lxy"
PublicFunctionDriveSerial(ByValsDrvAsString)AsLong'得到硬盘的序列号
DimRetValAsLong
DimstrAsString*MAX_FILENAME_LEN
Dimstr2AsString*MAX_FILENAME_LEN
DimaAsLong
DimbAsLong
CallGetVolumeInformation(sDrv&":",str,MAX_FILENAME_LEN,RetVal,a,b,str2,MAX_FILENAME_LEN)
DriveSerial=RetVal
EndFunction
PublicFunctionGetApplySerial()AsLong'根据c盘的序列号生成一个申请码
GetApplySerial=DriveSerial("c")
IfGetApplySerial<0ThenGetApplySerial=0-GetApplySerial
EndFunction
'根据申请码和密码表及密码得到序列号
PublicFunctiongetSerial(ByValSRCAsLong,ByValPASSWORDAsString)AsString
DimSourceStringAsString
DimNewSRCAsLong
ForI=0To30
If(SRCAnd2^I)=2^IThen
SourceString=SourceString+"1"
Else
SourceString=SourceString+"0"
EndIf
NextI
IfSRC<0Then
SourceString=SourceString+"1"
Else
SourceString=SourceString+"0"
EndIf
DimTableAsString
'==========================================================================
'参数Table是密码表,根据你的要求换成别的,不过长度要一致
'==========================================================================
'注意:这里的密码表变动后,对应的注册号生成器的密码表也要完全一致才能生成正确的注册号
Table="JSDJFKLUWRUOISDH;KSADJKLWQ;ABCDEFHIHL;KLADSDKJAGFWIHERQOWRLQH"
'==========================================================================
DimTableIndexAsInteger
DimResultAsString
DimMidWordAsString
DimMidWordValueAsByte
DimResultValueAsByte
Fort=1To1
ForI=1ToLen(SourceString)
MidWord=Mid(SourceString,I,1)
MidWordValue=Asc(MidWord)
TableIndex=TableIndex+1
IfTableIndex>Len(Table)ThenTableIndex=1
ResultValue=Asc(Mid(Table,TableIndex,1))ModMidWordValue
Result=Result+Hex(ResultValue)
NextI
SourceString=Result
Nextt
DimBitTORoolAsInteger
Fort=1ToLen(CStr(SRC))
BitTORool=SRCAnd2^t
ForI=1ToBitTORool
SourceString=Right(SourceString,1)_
+Left(SourceString,Len(SourceString)-1)
NextI
Nextt
IfPASSWORD=GETSERIALPASSWORDThen
getSerial=SourceString
Else
getSerial="你无权获得软件序列号"
EndIf
EndFunction
'验证序列号是否正确
PublicFunctionIsSerial(ByValSerialAsString)AsBoolean
IfSerial=getSerial(GetApplySerial(),GETSERIALPASSWORD)Then
IsSerial=True
Else
IsSerial=False
EndIf
EndFunction
PublicFunctioncheckSerial()
DimIIAsNewINI
II.FileName="D:akJFManageserial.ini"'INI文件名
II.AppName="SERIAL"'INI小节名称
II.KeyName="Serial"'INI项目名
Serial=II.GetINI
IfIsSerial(Serial)Then
checkSerial="通过注册码检查"
Else
checkSerial="没通过注册码检查,请在serial.ini文件中设置注册码"
II.KeyName="ApplySerial"'INI项目名
II.ValueStr=GetApplySerial()
II.WriteINI
EndIf
SetII=Nothing
EndFunction
PrivateConstMAX_FILENAME_LEN=256
PrivateConstGETSERIALPASSWORD="lxy"
PublicFunctionDriveSerial(ByValsDrvAsString)AsLong'得到硬盘的序列号
DimRetValAsLong
DimstrAsString*MAX_FILENAME_LEN
Dimstr2AsString*MAX_FILENAME_LEN
DimaAsLong
DimbAsLong
CallGetVolumeInformation(sDrv&":",str,MAX_FILENAME_LEN,RetVal,a,b,str2,MAX_FILENAME_LEN)
DriveSerial=RetVal
EndFunction
PublicFunctionGetApplySerial()AsLong'根据c盘的序列号生成一个申请码
GetApplySerial=DriveSerial("c")
IfGetApplySerial<0ThenGetApplySerial=0-GetApplySerial
EndFunction
'根据申请码和密码表及密码得到序列号
PublicFunctiongetSerial(ByValSRCAsLong,ByValPASSWORDAsString)AsString
DimSourceStringAsString
DimNewSRCAsLong
ForI=0To30
If(SRCAnd2^I)=2^IThen
SourceString=SourceString+"1"
Else
SourceString=SourceString+"0"
EndIf
NextI
IfSRC<0Then
SourceString=SourceString+"1"
Else
SourceString=SourceString+"0"
EndIf
DimTableAsString
'==========================================================================
'参数Table是密码表,根据你的要求换成别的,不过长度要一致
'==========================================================================
'注意:这里的密码表变动后,对应的注册号生成器的密码表也要完全一致才能生成正确的注册号
Table="JSDJFKLUWRUOISDH;KSADJKLWQ;ABCDEFHIHL;KLADSDKJAGFWIHERQOWRLQH"
'==========================================================================
DimTableIndexAsInteger
DimResultAsString
DimMidWordAsString
DimMidWordValueAsByte
DimResultValueAsByte
Fort=1To1
ForI=1ToLen(SourceString)
MidWord=Mid(SourceString,I,1)
MidWordValue=Asc(MidWord)
TableIndex=TableIndex+1
IfTableIndex>Len(Table)ThenTableIndex=1
ResultValue=Asc(Mid(Table,TableIndex,1))ModMidWordValue
Result=Result+Hex(ResultValue)
NextI
SourceString=Result
Nextt
DimBitTORoolAsInteger
Fort=1ToLen(CStr(SRC))
BitTORool=SRCAnd2^t
ForI=1ToBitTORool
SourceString=Right(SourceString,1)_
+Left(SourceString,Len(SourceString)-1)
NextI
Nextt
IfPASSWORD=GETSERIALPASSWORDThen
getSerial=SourceString
Else
getSerial="你无权获得软件序列号"
EndIf
EndFunction
'验证序列号是否正确
PublicFunctionIsSerial(ByValSerialAsString)AsBoolean
IfSerial=getSerial(GetApplySerial(),GETSERIALPASSWORD)Then
IsSerial=True
Else
IsSerial=False
EndIf
EndFunction
PublicFunctioncheckSerial()
DimIIAsNewINI
II.FileName="D:akJFManageserial.ini"'INI文件名
II.AppName="SERIAL"'INI小节名称
II.KeyName="Serial"'INI项目名
Serial=II.GetINI
IfIsSerial(Serial)Then
checkSerial="通过注册码检查"
Else
checkSerial="没通过注册码检查,请在serial.ini文件中设置注册码"
II.KeyName="ApplySerial"'INI项目名
II.ValueStr=GetApplySerial()
II.WriteINI
EndIf
SetII=Nothing
EndFunction
原作者:heraldboy
本文地址:http://www.45fan.com/dnjc/72987.html