- Offizieller Beitrag
Hi,
ich habe eine Funktion geschrieben, die eine Ausführung der Skript.exe auf bestimmte Kriterien beschränkt. Dies bewirkt, dass eine aktivierte Skript.exe nach einer Kopie nicht auf anderen PCs / etc. ausgeführt werden kann.
Die UDF (user defined function) schreibt bei der Aktivierung einen generierten verschlüsselten Code in die Registry. Anschließend wird
dieser Code im Skript entschlüsselt und überprüft. Bei keiner Übereinstimmung wird das Skript beendet.
Spoiler anzeigen
#include <String.au3>
; Added the option to specify whether it runs only on this windows, or this harddrive.
If _runOnlyOnThis("", "", -1, "test", 1) <> 1 Then Exit (0)
; Put your script code below here
[/autoit] [autoit][/autoit] [autoit]MsgBox(64, "Secured Program", "Yeah, the secured main-program started!" & _
@CRLF & @CRLF & "Thanks & and have fun!" & @CRLF & @CRLF & "Mega")
;===============================================================================
;
; Function Name: _runOnlyOnThis ...
; Description: Activation by parameter sets a unique registry key
; After a successful activation, checks for the regkey
; If correct go on, else Exit(0)
;
; Parameter(s): (Script) First time, the activation key
; (Func) $s_KeyName = RegKeyName
; $s_EncryptPassword = Encryption passphrase
; $i_EncryptLevel = Level (quantity)
; $s_ActivationKey = key which starts the func
; $i_Option (default =1)
;
; _runOnlyOnThis ... $i_Option
; 1 = Windows installtion (Date)
; 2 = HardDrive
;
; Return Value(s): On Success - Returns 1
; On Failure - Returns -1 RegWrite Problem,
; Returns -2 Not activated,
; Returns -3 Wrong registry key
; Returns -4 Couldn't DriveGetSerial
;
; Note(s): Basically useful to prevent user starting the script on
; non activated PCs
; String.au3 has to be included
;
; Author(s): Thorsten Meger
;
;===============================================================================
Func _runOnlyOnThis($s_KeyName, $s_EncryptPassword, $i_EncryptLevel, $s_ActivationKey, $i_option = 1)
If $s_KeyName = "" Then $s_KeyName = "Version"
If $s_EncryptPassword = "" Then $s_EncryptPassword = "thisPc"
If $i_EncryptLevel = -1 Then $i_EncryptLevel = 2
If $s_ActivationKey = "" Then $s_ActivationKey = "activate"
If $i_option <> 1 Or $i_option <> 2 Then $i_option = 1
If $i_option = 1 Then
Local $stringToCrypt = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate")
ElseIf $i_option = 2 Then
Local $stringToCrypt = DriveGetSerial(StringLeft(@SystemDir, 3))
If @error = 1 Then Return -4
EndIf
Local $crypted = _StringEncrypt(1, $stringToCrypt, $s_EncryptPassword, $i_EncryptLevel)
If $cmdLine[0] > 0 And $cmdLine[1] = $s_ActivationKey Then
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\" & StringLeft(@ScriptName, StringLen(@ScriptName) - 4), $s_KeyName, "REG_SZ", _
StringTrimLeft($crypted, 4))
Return -1
ElseIf RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\" & StringLeft(@ScriptName, StringLen(@ScriptName) - 4), $s_KeyName) = "" Then
MsgBox(64, "Error", "You are not allowed to run this program!", 5)
Return -2
ElseIf RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\" & StringLeft(@ScriptName, StringLen(@ScriptName) - 4), $s_KeyName) <> _
(StringTrimLeft($crypted, 4)) Then
MsgBox(64, "Error", "You are not allowed to run this program on this computer!", 5)
Return -3
EndIf
Return 1
EndFunc ;==>_runOnlyOnThis
Aktivierungsskript:
Spoiler anzeigen
_activateScript("RunOnlyOnThisPc.exe", "test")
[/autoit] [autoit][/autoit] [autoit];===============================================================================
;
; Function Name: _activateScript
; Description: Activates the script which is protected by _runOnlyOnThisPC
;
; Parameter(s): $s_programName = name (script.exe)
; $s_ActivationKey = key which starts the func
;
; Return Value(s): Non
;
; Note(s): Basically useful to start(activate) the _runOnlyOnThisPC
; protected script
; Should be on own script.exe in the same folder!
;
; Author(s): Thorsten Meger
;
;===============================================================================
Func _activateScript($s_programName, $s_ActivationKey)
Run(@ScriptDir & "\" & $s_programName & " " & $s_ActivationKey)
Local $cmdfile
FileDelete(@TempDir & "\scratch.cmd")
$cmdfile = ':loop' & @CRLF _
& 'del "' & @ScriptFullPath & '"' & @CRLF _
& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
& 'del ' & @TempDir & '\scratch.cmd'
FileWrite(@TempDir & "\scratch.cmd", $cmdfile)
Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE)
EndFunc;==>_activateScript
Mit der Bitte um Feedback...
So long,
Mega
bernd670: Hab mal die PHP-Tags durch AutoIt-Tags ersetzt.