У меня есть 2 скрипта, один для клиента, другой для меня. Скрипт " Для клиента " выдает ключ, который я активирую в программе " Для меня ". Вопрос такой: можно ли сделать как то, что бы ключу можно было задавать время длительности его действия.
Для меня:
Программа для пользователя:
Для меня:
Код:
$form1 = GUICreate("Key", 397, 134, 192, 306)
$label1 = GUICtrlCreateLabel("Ключ пользователя :", 12, 18, 103, 17)
$label2 = GUICtrlCreateLabel("Ключ активации :", 16, 54, 98, 17)
$userid = GUICtrlCreateInput("", 120, 15, 268, 21)
$vipkey = GUICtrlCreateInput("", 120, 51, 268, 21)
$button1 = GUICtrlCreateButton("Генерировать Ключ", 6, 87, 183, 34)
$button2 = GUICtrlCreateButton("Копировать в буфер обмана", 201, 87, 183, 34)
GUISetState(@SW_SHOW)
While 1
$nmsg = GUIGetMsg()
Switch $nmsg
Case -3
Exit
Case $button1
GUICtrlSetData($vipkey, _getkey(GUICtrlRead($userid)))
Case $button2
ClipPut(GUICtrlRead($vipkey))
EndSwitch
WEnd
Func _getkey($userid)
$hash = __md5($userid)
Return StringMid($hash, 1, 7) & "-" & StringMid($hash, 9, 7) & "-" & StringMid($hash, 13, 7) & "-" & StringMid($hash, 17, 7) & "-" & StringMid($hash, 21, 7)
EndFunc
Func _uniquehardwareid($iflags = 0)
Local $oservice = ObjGet("winmgmts:\\.\root\cimv2")
If NOT IsObj($oservice) Then
Return SetError(1, 0, "")
EndIf
Local $oitems, $hash, $text, $hw = "", $result = 0
$oitems = $oservice.execquery("SELECT * FROM Win32_ComputerSystemProduct")
If NOT IsObj($oitems) Then
Return SetError(2, 0, "")
EndIf
For $property In $oitems
$hw &= $property.identifyingnumber
$hw &= $property.name
$hw &= $property.skunumber
$hw &= $property.uuid
$hw &= $property.vendor
$hw &= $property.version
Next
$hw = StringStripWS($hw, 8)
If NOT $hw Then
Return SetError(3, 0, "")
EndIf
If BitAND($iflags, 1) Then
$oitems = $oservice.execquery("SELECT * FROM Win32_BIOS")
If NOT IsObj($oitems) Then
Return SetError(2, 0, "")
EndIf
$text = ""
For $property In $oitems
$text &= $property.identificationcode
$text &= $property.manufacturer
$text &= $property.name
$text &= $property.serialnumber
$text &= $property.smbiosmajorversion
$text &= $property.smbiosminorversion
Next
$text = StringStripWS($text, 8)
If $text Then
$result += 1
$hw &= $text
EndIf
EndIf
If BitAND($iflags, 2) Then
$oitems = $oservice.execquery("SELECT * FROM Win32_Processor")
If NOT IsObj($oitems) Then
Return SetError(2, 0, "")
EndIf
$text = ""
For $property In $oitems
$text &= $property.architecture
$text &= $property.family
$text &= $property.level
$text &= $property.manufacturer
$text &= $property.name
$text &= $property.processorid
$text &= $property.revision
$text &= $property.version
Next
$text = StringStripWS($text, 8)
If $text Then
$result += 2
$hw &= $text
EndIf
EndIf
$hash = __md5($hw)
If NOT $hash Then
Return SetError(4, 0, "")
EndIf
Return SetError(0, $result, $hash)
Return SetError(0, $result, "{" & StringMid($hash, 1, 8) & "-" & StringMid($hash, 9, 4) & "-" & StringMid($hash, 13, 4) & "-" & StringMid($hash, 17, 4) & "-" & StringMid($hash, 21, 12) & "}")
EndFunc
Func __md5($sdata)
Local $ret, $hprov, $hhash, $tdata, $error = 1
$hprov = DllCall("advapi32.dll", "int", "CryptAcquireContextW", "ptr*", 0, "ptr", 0, "ptr", 0, "dword", 3, "dword", -268435456)
If (@error) OR (NOT $hprov[0]) Then
Return ""
EndIf
Do
$hhash = DllCall("advapi32.dll", "int", "CryptCreateHash", "ptr", $hprov[1], "uint", 32771, "ptr", 0, "dword", 0, "ptr*", 0)
If (@error) OR (NOT $hprov[0]) Then
$hhash = 0
ExitLoop
EndIf
$hhash = $hhash[5]
$tdata = DllStructCreate("byte[" & BinaryLen($sdata) & "]")
DllStructSetData($tdata, 1, $sdata)
$ret = DllCall("advapi32.dll", "int", "CryptHashData", "ptr", $hhash, "ptr", DllStructGetPtr($tdata), "dword", DllStructGetSize($tdata), "dword", 1)
If (@error) OR (NOT $ret[0]) Then
ExitLoop
EndIf
$tdata = DllStructCreate("byte[16]")
$ret = DllCall("advapi32.dll", "int", "CryptGetHashParam", "ptr", $hhash, "dword", 2, "ptr", DllStructGetPtr($tdata), "dword*", 16, "dword", 0)
If (@error) OR (NOT $ret[0]) Then
ExitLoop
EndIf
$error = 0
Until 1
If $hhash Then
DllCall("advapi32.dll", "int", "CryptDestroyHash", "ptr", $hhash)
EndIf
If $error Then
Return ""
EndIf
Return StringTrimLeft(DllStructGetData($tdata, 1), 2)
EndFunc
Программа для пользователя:
Код:
$INI = @ScriptDir & "\key.ini"
if iniread($INI, "authorization", "key", "") = "" Then
IniWrite($INI, "authorization", "key", "")
EndIf
$key = IniRead($INI, "authorization", "key", "")
if StringRegExp($key,_GetKey(_UniqueHardwareID(0x01 + 0x02))) = 1 Then
MsgBox(0,"","ключ найден")
_start()
Else
MsgBox(0,"","ключ не найден")
ClipPut(_UniqueHardwareID(0x01 + 0x02))
MsgBox(0,"","ключ скопирован в буфер обмена, отправьте его автору")
_authorization()
EndIf
Func _start()
;ваша программа
EndFunc
Func _authorization()
$key = InputBox("Проверка безопасности", "Введите ключ", "")
if $key = _GetKey(_UniqueHardwareID(0x01 + 0x02)) Then
IniWrite($Ini, "authorization", "key", $key)
MsgBox(0,"Внимание","Ключ указан верно")
_start()
Else
MsgBox(0,"Внимание","Неверный ключ")
exit
EndIf
EndFunc
Func _GetKey($userid)
$hash = __md5($userid)
Return StringMid($hash, 1, 7) & "-" & StringMid($hash, 9, 7) & "-" & StringMid($hash, 13, 7) & "-" & StringMid($hash, 17, 7) & "-" & StringMid($hash, 21, 7)
EndFunc
Func _UniqueHardwareID($iFlags = 0)
Local $oService = ObjGet('winmgmts:\\.\root\cimv2')
If Not IsObj($oService) Then
Return SetError(1, 0, '')
EndIf
Local $oItems, $Hash, $Text, $Hw = '', $Result = 0
$oItems = $oService.ExecQuery('SELECT * FROM Win32_ComputerSystemProduct')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
For $Property In $oItems
$Hw &= $Property.IdentifyingNumber
$Hw &= $Property.Name
$Hw &= $Property.SKUNumber
$Hw &= $Property.UUID
$Hw &= $Property.Vendor
$Hw &= $Property.Version
Next
$Hw = StringStripWS($Hw, 8)
If Not $Hw Then
Return SetError(3, 0, '')
EndIf
If BitAND($iFlags, 0x0001) Then
$oItems = $oService.ExecQuery('SELECT * FROM Win32_BIOS')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
$Text = ''
For $Property In $oItems
$Text &= $Property.IdentificationCode
$Text &= $Property.Manufacturer
$Text &= $Property.Name
$Text &= $Property.SerialNumber
$Text &= $Property.SMBIOSMajorVersion
$Text &= $Property.SMBIOSMinorVersion
Next
$Text = StringStripWS($Text, 8)
If $Text Then
$Result += 0x0001
$Hw &= $Text
EndIf
EndIf
If BitAND($iFlags, 0x0002) Then
$oItems = $oService.ExecQuery('SELECT * FROM Win32_Processor')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
$Text = ''
For $Property In $oItems
$Text &= $Property.Architecture
$Text &= $Property.Family
$Text &= $Property.Level
$Text &= $Property.Manufacturer
$Text &= $Property.Name
$Text &= $Property.ProcessorId
$Text &= $Property.Revision
$Text &= $Property.Version
Next
$Text = StringStripWS($Text, 8)
If $Text Then
$Result += 0x0002
$Hw &= $Text
EndIf
EndIf
$Hash = __MD5($Hw)
If Not $Hash Then
Return SetError(4, 0, '')
EndIf
Return SetError(0, $Result, $Hash)
Return SetError(0, $Result, '{' & StringMid($Hash, 1, 8) & '-' & StringMid($Hash, 9, 4) & '-' & StringMid($Hash, 13, 4) & '-' & StringMid($Hash, 17, 4) & '-' & StringMid($Hash, 21, 12) & '}')
EndFunc
Func __MD5($sData)
Local $Ret, $hProv, $hHash, $tData, $Error = 1
$hProv = DllCall('advapi32.dll', 'int', 'CryptAcquireContextW', 'ptr*', 0, 'ptr', 0, 'ptr', 0, 'dword', 3, 'dword', 0xF0000000)
If (@error) Or (Not $hProv[0]) Then
Return ''
EndIf
Do
$hHash = DllCall('advapi32.dll', 'int', 'CryptCreateHash', 'ptr', $hProv[1], 'uint', 0x00008003, 'ptr', 0, 'dword', 0, 'ptr*', 0)
If (@error) Or (Not $hProv[0]) Then
$hHash = 0
ExitLoop
EndIf
$hHash = $hHash[5]
$tData = DllStructCreate('byte[' & BinaryLen($sData) & ']')
DllStructSetData($tData, 1, $sData)
$Ret = DllCall('advapi32.dll', 'int', 'CryptHashData', 'ptr', $hHash, 'ptr', DllStructGetPtr($tData), 'dword', DllStructGetSize($tData), 'dword', 1)
If (@error) Or (Not $Ret[0]) Then
ExitLoop
EndIf
$tData = DllStructCreate('byte[16]')
$Ret = DllCall('advapi32.dll', 'int', 'CryptGetHashParam', 'ptr', $hHash, 'dword', 2, 'ptr', DllStructGetPtr($tData), 'dword*', 16, 'dword', 0)
If (@error) Or (Not $Ret[0]) Then
ExitLoop
EndIf
$Error = 0
Until 1
If $hHash Then
DllCall('advapi32.dll', 'int', 'CryptDestroyHash', 'ptr', $hHash)
EndIf
If $Error Then
Return ''
EndIf
Return StringTrimLeft(DllStructGetData($tData, 1), 2)
EndFunc