HTML Code:
Global $smtpserver = "YOUR_SERVER"
Global $sendusername = "YOUR_SERVER_USER_NAME"
Global $sendpassword = "YOUR_SERVER_USERS_PASSWORD"
Func xprotec($d_mail, $d_program, $u_price = 0, $u_trial = 0, $u_license = 1, $d_license = 1, $d_paypal = 1, $d_link = 1, $u_return = 1)
[COLOR="Red"]If @Compiled <> 1 AND $d_license <> 1 Then Return SetError(1, -1, "Not a Compiled Program")[/COLOR]
If $d_program <> StringTrimRight(@ScriptName, 4) Then merror("ERROR - Not a Valid Program Name ", 1, 1)
Local $i_rand, $u_info, $vreg, $u_payed, $rtemp = @TempDir & "\XTemp.txt", $m_server = "@ClickTask.com", $nd_mail = $d_mail, $encrypt = "Fudge", $ver = "f1.0.0"
Local $p_program = $d_program, $sc = @ComputerName, $sd = @HomeDrive, $r_owner = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "RegisteredOwner"), $ss = @ScriptName
Local $d_1 = _stringencryptor(1, $d_mail, $encrypt), $d_2 = _stringencryptor(1, "X" & (StringInStr($d_mail, "@") * (StringLen($d_mail) - 2)) + ((StringLen($d_mail) - 2) * 7), (StringLen($d_1) - 9))
Local $rand = Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(100, 999, 1) & "-" & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(100, 999, 1) & "-" & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(100, 999, 1) & "-" & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(100, 999, 1)
Local $p_3 = StringMid(_stringencryptor(1, "X" & (StringLeft(DriveGetSerial($sd), 6) + StringLen($sc)) & StringLen($sc), $encrypt & "n", 2), StringLen($sc) / 2, 16), $f_days = 0, $f_file = @SystemDir & "\winopsys.dat"
If StringInStr($ss, "XProTec") Then Return merror("Not a Valid Developer Program ", 2, 1)
If NOT StringInStr($d_mail, "@") AND NOT StringInStr($d_mail, ".") Then Return merror("Not a Valid Developer Email ", 3, 1)
If $u_license <> 1 AND $u_license <> 2 AND $u_license <> 3 Then Return merror("Not a Valid User License Number (1,2 or 3) ", 4, 1)
If $d_license <> $d_2 Then merror("Please Register as Developer" & @CRLF & @CRLF & "Dev Email = " & $d_mail & " " & @CRLF & "Dev License = " & $d_2 & " " & @CRLF & @CRLF, " Free # ...Valuater", 1)
While 1
If Ping("www.Autoit3.com", 4000) > 0 Then ExitLoop
If MsgBox(262149, "Connection Error", "An Internet Connection is Required ", 10) = 2 Then Exit
WEnd
$x_read001 = RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "001")
$x_read004 = RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "004")
If $x_read001 = "" AND $x_read004 = "" Then
If MsgBox(262209, $p_program, "To Register as User, an Email will be sent Immediately to you " & @CRLF & @CRLF & "Please Click OK to continue " & @CRLF) <> 1 Then Exit
Do
$u_mail = qbox($p_program, "Please Type in your Email Address " & @CRLF & @CRLF & "If not, you will need to restart - " & $p_program & " ")
Until StringInStr($u_mail, "@") AND StringInStr($u_mail, ".")
$text = "Please copy the Validation Code below" & @CRLF & @CRLF & "Owner = " & $r_owner & @CRLF & "Program = " & $p_program & @CRLF & "Validation Date = " & _datetimeformat(_nowcalc(), 1) & @CRLF & "Validation Code = " & $rand & @CRLF & @CRLF & " Thank You!" & @CRLF & $p_program
memailer($p_program & $m_server, $u_mail, $nd_mail, $p_program & " Validation Code", $text)
Do
$input1 = qbox($p_program, "Please Copy and Paste the Validation Code from the Email here " & @CRLF & "If not, you will need to restart - " & $p_program & " ")
Until $input1 = $rand
Local $x_read003 = $u_mail, $x_read004 = _nowcalc(), $x_read005 = "", $x_read006 = "", $x_read007 = ""
IniWrite($f_file, "Security", $p_program, _stringencryptor(1, _nowcalc(), (StringLen($d_1) - 13)))
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "001", "REG_SZ", $d_mail)
If $d_license <> $d_2 Then RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "002", "REG_SZ", "Developer Not Licensed")
If $d_license = $d_2 Then RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "002", "REG_SZ", "Licensed Developer")
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "003", "REG_SZ", $u_mail)
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "004", "REG_SZ", _stringencryptor(1, _nowcalc(), (StringLen($d_1) - 13)))
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "005", "REG_SZ", "")
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "006", "REG_SZ", "")
RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "007", "REG_SZ", "")
Else
If $x_read001 <> $d_mail Then merror("Not the Registered Developer Email ", 5, 1)
If $d_license <> $d_2 Then RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "002", "REG_SZ", "Developer Not Licensed")
If $d_license = $d_2 Then RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "002", "REG_SZ", "Licensed Developer")
$x_read003 = RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "003")
$x_read004 = _stringencryptor(0, RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "004"), (StringLen($d_1) - 13))
$x_read005 = _stringencryptor(0, RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "005"), $encrypt & "7")
$x_read006 = _stringencryptor(0, RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "006"), $encrypt & "2")
$x_read007 = RegRead("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "007")
EndIf
If InetGet($d_link & "Blacklist.txt", $rtemp, 1) = 1 Then
$itemp = FileRead($rtemp)
FileDelete($rtemp)
If StringInStr($itemp, $x_read003) OR StringInStr($itemp, $nd_mail) Then merror("This program has been abused and will now close ", 6, 1)
EndIf
If $u_trial = 0 AND $u_price = 0 Then Return SetError(0, 0, "Free Licensed")
If $u_license = 1 AND $x_read005 = $x_read003 Then Return SetError(0, 1, "Email Licensed")
If $u_license = 2 AND $x_read006 = $r_owner Then Return SetError(0, 2, "Owner Licensed")
If $u_license = 3 AND $x_read007 = $p_3 Then Return SetError(0, 3, "Computer Licensed")
If $u_license = 1 Then $u_info = "Your E-Mail "
If $u_license = 1 Then $i_rand = _stringencryptor(1, $x_read003, $encrypt & "7")
If $u_license = 2 Then $u_info = "Windows Registered Owner "
If $u_license = 2 Then $i_rand = _stringencryptor(1, $r_owner, $encrypt & "2")
If $u_license = 3 Then $u_info = "One Computer Only "
If $u_license = 3 Then $i_rand = $p_3
$t_days = _datediff("D", $x_read004, _nowcalc())
$t = FileGetTime(_stringencryptor(0, IniRead($f_file, "Security", $p_program, _nowcalc()), (StringLen($d_1) - 13)))
If NOT @error Then $f_days = _datediff("D", $t[0] & "/" & $t[1] & "/" & $t[2], _nowcalc())
If $f_days > $t_days Then $t_days = $f_days
If $t_days < 0 OR $t_days > 3600 Then merror("ERROR - Validation Date ", 7, 1)
If $d_license <> $d_2 AND $t_days > 90 Then merror("Developer Trial Period has Expired ", 9, 1)
If $u_trial <> 0 AND $u_price = 0 AND $t_days > $u_trial Then merror($p_program & "'s Trial Period has Expired ", 8, 1)
If $u_trial <> 0 AND $t_days > ($u_trial / 2) AND $t_days <= $u_trial Then $u_payed = mregister($p_program, $u_price, $u_trial, $u_license, $t_days, $d_paypal, $u_info, $i_rand, 0)
If $u_trial = 0 AND $u_price <> 0 OR $t_days > $u_trial Then $u_payed = mregister($p_program, $u_price, $u_trial, $u_license, $t_days, $d_paypal, $u_info, $i_rand, $u_return)
If $u_payed = 1 AND $u_license >= 1 AND $u_license <= 3 Then RegWrite("HKCU\Software\Microsoft\Windows\Current Version\Settings\ClickTask.com\X-" & $p_program, "00" & ($u_license + 4), "REG_SZ", $i_rand)
If $u_payed = 1 Then $text = "Please save this Registration Code Page" & @CRLF & @CRLF & "Owner = " & $r_owner & @CRLF & "Program = " & $p_program & @CRLF & "Registration Date = " & _datetimeformat(_nowcalc(), 1) & @CRLF & "Registration Code = " & $i_rand & @CRLF & @CRLF & " Thank You!" & @CRLF & $p_program
If $u_payed = 1 Then memailer($p_program & $m_server, $x_read003, $nd_mail, $p_program & " Registration Code", $text)
If $u_payed = 1 Then MsgBox(64, $p_program, " You are now registered and a confirmation email has been sent to you " & @CRLF & @CRLF & "..... Thank You ! ", 5)
If $u_payed = 1 Then Return SetError(0, 4, "License Paid")
If $u_trial = 0 AND $u_price <> 0 OR $t_days > $u_trial Then Return SetError(0, 6, "Freeware Limited")
Return SetError(0, 5, "License Not Paid")
EndFunc
Func mregister($prog, $u_p, $u_t, $u_l, $t_d, $d_p, $uinfo, $irand, $rfatal = 0)
Local $pr1 = "Trial Period = " & $u_t & " Days " & @CRLF & "License Type = " & $uinfo & @CRLF & "Register Fee = $" & $u_p
Local $pr2 = " " & @CRLF & "Days Since Validation = " & $t_d & @CRLF & @CRLF & "Would you like to Register Now? " & @CRLF & @CRLF
Local $pr3 = "*Yes* to Register Now!" & @CRLF & "*No* to use your previous Registration Number. " & @CRLF & "*Cancel* to Quit Registration." & @CRLF
$u_ans = MsgBox(262147, $prog, $pr1 & $pr2 & $pr3)
If $u_ans = 6 Then
WinMinimizeAll()
$pid = Run('C:\Program Files\Internet Explorer\iexplore.exe "' & $d_p & '"', "", @SW_SHOW)
WinWaitActive("")
Local $handle = WinGetHandle($pid), $shtml = "", $loop = 0
While ProcessExists($pid)
Sleep(3000)
If ProcessExists($pid) = 0 Then ExitLoop
If NOT StringInStr(WinGetTitle($handle), "PayPal") AND NOT StringInStr(WinGetTitle($handle), "DreamHost") Then
If $loop = 5 Then ExitLoop
$loop = $loop + 1
Else
$loop = 0
EndIf
If StringInStr(WinGetTitle($handle), "Thank you for your payment") Then Return 1
WEnd
ProcessClose($pid)
EndIf
If $u_ans = 7 Then
Do
$input1 = qbox($prog, "Please Paste your Registration Code below " & @CRLF & "License Type = " & $uinfo & " " & @CRLF & "If not, you will need to restart - " & $prog & " ")
Until $input1 = $irand
Return 1
EndIf
If $rfatal Then Exit
Return 0
EndFunc
Func memailer($e_sender, $e_recipient, $e_ccaddress, $e_subject, $e_text)
$omyerror = ObjEvent("AutoIt.Error", "MyErrFunc")
$objmessage = ObjCreate("CDO.Message")
With $objmessage
.subject = $e_subject
.sender = $e_sender
.from = $e_sender
.to = $e_recipient
.cc = $e_ccaddress
.textbody = $e_text
EndWith
With $objmessage.configuration.fields
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $smtpserver
.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $sendusername
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $sendpassword
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.update
EndWith
$objmessage.send
If @error Then myerrfunc()
$omyerror = ""
$objmessage = ""
EndFunc
Func qbox($t1, $l1)
$qbox = InputBox($t1, $l1, "", "", 300, 150)
If @error = 1 Then Exit
Return $qbox
EndFunc
Func merror($stext, $ret = 0, $ifatal = 0)
MsgBox(48 + 4096 + 262144, "*XProTec*", $stext & " #" & $ret & " ")
If $ifatal Then Exit
EndFunc
Func myerrfunc()
MsgBox(262209, "COM / Internal Error", "This Program has been interupted by a Fatal COM Error ")
Exit
EndFunc
Func _inetgetsources($s_url, $s_header = "")
If StringLeft($s_url, 7) <> "http://" AND StringLeft($s_url, 8) <> "https://" Then $s_url = "http://" & $s_url
Local $h_dll = DllOpen("wininet.dll"), $ai_irf, $s_buf = ""
Local $ai_io = DllCall($h_dll, "int", "InternetOpen", "str", "AutoIt v3", "int", 0, "int", 0, "int", 0, "int", 0)
If @error OR $ai_io[0] = 0 Then
DllClose($h_dll)
SetError(1)
Return ""
EndIf
Local $ai_iou = DllCall($h_dll, "int", "InternetOpenUrl", "int", $ai_io[0], "str", $s_url, "str", $s_header, "int", StringLen($s_header), "int", -2147483648, "int", 0)
If @error OR $ai_iou[0] = 0 Then
DllCall($h_dll, "int", "InternetCloseHandle", "int", $ai_io[0])
DllClose($h_dll)
SetError(1)
Return ""
EndIf
Local $v_struct = DllStructCreate("udword")
DllStructSetData($v_struct, 1, 1)
While DllStructGetData($v_struct, 1) <> 0
$ai_irf = DllCall($h_dll, "int", "InternetReadFile", "int", $ai_iou[0], "str", "", "int", 256, "ptr", DllStructGetPtr($v_struct))
$s_buf &= StringLeft($ai_irf[2], DllStructGetData($v_struct, 1))
WEnd
DllCall($h_dll, "int", "InternetCloseHandle", "int", $ai_iou[0])
DllCall($h_dll, "int", "InternetCloseHandle", "int", $ai_io[0])
DllClose($h_dll)
Return $s_buf
EndFunc
Func _stringencryptor($i_encrypt, $s_encrypttext, $s_encryptpassword, $i_encryptlevel = 1)
If $i_encrypt <> 0 AND $i_encrypt <> 1 Then
SetError(1)
Return ""
ElseIf $s_encrypttext = "" OR $s_encryptpassword = "" Then
SetError(1)
Return ""
Else
If Number($i_encryptlevel) <= 0 OR Int($i_encryptlevel) <> $i_encryptlevel Then $i_encryptlevel = 1
Local $v_encryptmodified, $i_encryptcounth, $i_encryptcountg, $v_encryptswap, $av_encryptbox[256][2], $i_encryptcounta
Local $i_encryptcountb, $i_encryptcountc, $i_encryptcountd, $i_encryptcounte, $v_encryptcipher, $v_encryptcipherby
If $i_encrypt = 1 Then
For $i_encryptcountf = 0 To $i_encryptlevel Step 1
$i_encryptcountg = ""
$i_encryptcounth = ""
$v_encryptmodified = ""
For $i_encryptcountg = 1 To StringLen($s_encrypttext)
If $i_encryptcounth = StringLen($s_encryptpassword) Then
$i_encryptcounth = 1
Else
$i_encryptcounth = $i_encryptcounth + 1
EndIf
$v_encryptmodified = $v_encryptmodified & Chr(BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcountg, 1)), Asc(StringMid($s_encryptpassword, $i_encryptcounth, 1)), 255))
Next
$s_encrypttext = $v_encryptmodified
$i_encryptcounta = ""
$i_encryptcountb = 0
$i_encryptcountc = ""
$i_encryptcountd = ""
$i_encryptcounte = ""
$v_encryptcipherby = ""
$v_encryptcipher = ""
$v_encryptswap = ""
$av_encryptbox = ""
Local $av_encryptbox[256][2]
For $i_encryptcounta = 0 To 255
$av_encryptbox[$i_encryptcounta][1] = Asc(StringMid($s_encryptpassword, Mod($i_encryptcounta, StringLen($s_encryptpassword)) + 1, 1))
$av_encryptbox[$i_encryptcounta][0] = $i_encryptcounta
Next
For $i_encryptcounta = 0 To 255
$i_encryptcountb = Mod(($i_encryptcountb + $av_encryptbox[$i_encryptcounta][0] + $av_encryptbox[$i_encryptcounta][1]), 256)
$v_encryptswap = $av_encryptbox[$i_encryptcounta][0]
$av_encryptbox[$i_encryptcounta][0] = $av_encryptbox[$i_encryptcountb][0]
$av_encryptbox[$i_encryptcountb][0] = $v_encryptswap
Next
For $i_encryptcounta = 1 To StringLen($s_encrypttext)
$i_encryptcountc = Mod(($i_encryptcountc + 1), 256)
$i_encryptcountd = Mod(($i_encryptcountd + $av_encryptbox[$i_encryptcountc][0]), 256)
$i_encryptcounte = $av_encryptbox[Mod(($av_encryptbox[$i_encryptcountc][0] + $av_encryptbox[$i_encryptcountd][0]), 256)][0]
$v_encryptcipherby = BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcounta, 1)), $i_encryptcounte)
$v_encryptcipher = $v_encryptcipher & Hex($v_encryptcipherby, 2)
Next
$s_encrypttext = $v_encryptcipher
Next
Else
For $i_encryptcountf = 0 To $i_encryptlevel Step 1
$i_encryptcountb = 0
$i_encryptcountc = ""
$i_encryptcountd = ""
$i_encryptcounte = ""
$v_encryptcipherby = ""
$v_encryptcipher = ""
$v_encryptswap = ""
$av_encryptbox = ""
Local $av_encryptbox[256][2]
For $i_encryptcounta = 0 To 255
$av_encryptbox[$i_encryptcounta][1] = Asc(StringMid($s_encryptpassword, Mod($i_encryptcounta, StringLen($s_encryptpassword)) + 1, 1))
$av_encryptbox[$i_encryptcounta][0] = $i_encryptcounta
Next
For $i_encryptcounta = 0 To 255
$i_encryptcountb = Mod(($i_encryptcountb + $av_encryptbox[$i_encryptcounta][0] + $av_encryptbox[$i_encryptcounta][1]), 256)
$v_encryptswap = $av_encryptbox[$i_encryptcounta][0]
$av_encryptbox[$i_encryptcounta][0] = $av_encryptbox[$i_encryptcountb][0]
$av_encryptbox[$i_encryptcountb][0] = $v_encryptswap
Next
For $i_encryptcounta = 1 To StringLen($s_encrypttext) Step 2
$i_encryptcountc = Mod(($i_encryptcountc + 1), 256)
$i_encryptcountd = Mod(($i_encryptcountd + $av_encryptbox[$i_encryptcountc][0]), 256)
$i_encryptcounte = $av_encryptbox[Mod(($av_encryptbox[$i_encryptcountc][0] + $av_encryptbox[$i_encryptcountd][0]), 256)][0]
$v_encryptcipherby = BitXOR(Dec(StringMid($s_encrypttext, $i_encryptcounta, 2)), $i_encryptcounte)
$v_encryptcipher = $v_encryptcipher & Chr($v_encryptcipherby)
Next
$s_encrypttext = $v_encryptcipher
$i_encryptcountg = ""
$i_encryptcounth = ""
$v_encryptmodified = ""
For $i_encryptcountg = 1 To StringLen($s_encrypttext)
If $i_encryptcounth = StringLen($s_encryptpassword) Then
$i_encryptcounth = 1
Else
$i_encryptcounth = $i_encryptcounth + 1
EndIf
$v_encryptmodified = $v_encryptmodified & Chr(BitXOR(Asc(StringMid($s_encrypttext, $i_encryptcountg, 1)), Asc(StringMid($s_encryptpassword, $i_encryptcounth, 1)), 255))
Next
$s_encrypttext = $v_encryptmodified
Next
EndIf
Return $s_encrypttext
EndIf
EndFunc
Func _nowcalc()
Return (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)
EndFunc
Func _datetimeformat($sdate, $stype)
Local $asdatepart[4]
Local $astimepart[4]
Local $stempdate = ""
Local $stemptime = ""
Local $sam
Local $spm
Local $iwday
Local $lngx
If NOT _dateisvalid($sdate) Then
SetError(1)
Return ("")
EndIf
If $stype < 0 OR $stype > 5 OR NOT IsInt($stype) Then
SetError(2)
Return ("")
EndIf
_datetimesplit($sdate, $asdatepart, $astimepart)
Switch $stype
Case 0
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 31, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stempdate = $lngx[3]
Else
$stempdate = "M/d/yyyy"
EndIf
If $astimepart[0] > 1 Then
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 4099, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stemptime = $lngx[3]
Else
$stemptime = "h:mm:ss tt"
EndIf
EndIf
Case 1
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 32, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stempdate = $lngx[3]
Else
$stempdate = "dddd, MMMM dd, yyyy"
EndIf
Case 2
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 31, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stempdate = $lngx[3]
Else
$stempdate = "M/d/yyyy"
EndIf
Case 3
If $astimepart[0] > 1 Then
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 4099, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stemptime = $lngx[3]
Else
$stemptime = "h:mm:ss tt"
EndIf
EndIf
Case 4
If $astimepart[0] > 1 Then
$stemptime = "hh:mm"
EndIf
Case 5
If $astimepart[0] > 1 Then
$stemptime = "hh:mm:ss"
EndIf
EndSwitch
If $stempdate <> "" Then
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 29, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stemptime = StringReplace($stemptime, "/", $lngx[3])
EndIf
$iwday = _datetodayofweek($asdatepart[1], $asdatepart[2], $asdatepart[3])
$asdatepart[3] = StringRight("0" & $asdatepart[3], 2)
$asdatepart[2] = StringRight("0" & $asdatepart[2], 2)
$stempdate = StringReplace($stempdate, "d", "@")
$stempdate = StringReplace($stempdate, "m", "#")
$stempdate = StringReplace($stempdate, "y", "&")
$stempdate = StringReplace($stempdate, "@@@@", _datedayofweek($iwday, 0))
$stempdate = StringReplace($stempdate, "@@@", _datedayofweek($iwday, 1))
$stempdate = StringReplace($stempdate, "@@", $asdatepart[3])
$stempdate = StringReplace($stempdate, "@", StringReplace(StringLeft($asdatepart[3], 1), "0", "") & StringRight($asdatepart[3], 1))
$stempdate = StringReplace($stempdate, "####", _datemonthofyear($asdatepart[2], 0))
$stempdate = StringReplace($stempdate, "###", _datemonthofyear($asdatepart[2], 1))
$stempdate = StringReplace($stempdate, "##", $asdatepart[2])
$stempdate = StringReplace($stempdate, "#", StringReplace(StringLeft($asdatepart[2], 1), "0", "") & StringRight($asdatepart[2], 1))
$stempdate = StringReplace($stempdate, "&&&&", $asdatepart[1])
$stempdate = StringReplace($stempdate, "&&", StringRight($asdatepart[1], 2))
EndIf
If $stemptime <> "" Then
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 40, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$sam = $lngx[3]
Else
$sam = "AM"
EndIf
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 41, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$spm = $lngx[3]
Else
$spm = "PM"
EndIf
$lngx = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", 1024, "long", 30, "str", "", "long", 255)
If NOT @error AND $lngx[0] <> 0 Then
$stemptime = StringReplace($stemptime, ":", $lngx[3])
EndIf
If StringInStr($stemptime, "tt") Then
If $astimepart[1] < 12 Then
$stemptime = StringReplace($stemptime, "tt", $sam)
If $astimepart[1] = 0 Then $astimepart[1] = 12
Else
$stemptime = StringReplace($stemptime, "tt", $spm)
If $astimepart[1] > 12 Then $astimepart[1] = $astimepart[1] - 12
EndIf
EndIf
$astimepart[1] = StringRight("0" & $astimepart[1], 2)
$astimepart[2] = StringRight("0" & $astimepart[2], 2)
$astimepart[3] = StringRight("0" & $astimepart[3], 2)
$stemptime = StringReplace($stemptime, "hh", StringFormat("%02d", $astimepart[1]))
$stemptime = StringReplace($stemptime, "h", StringReplace(StringLeft($astimepart[1], 1), "0", "") & StringRight($astimepart[1], 1))
$stemptime = StringReplace($stemptime, "mm", StringFormat("%02d", $astimepart[2]))
$stemptime = StringReplace($stemptime, "ss", StringFormat("%02d", $astimepart[3]))
$stempdate = StringStripWS($stempdate & " " & $stemptime, 3)
EndIf
Return ($stempdate)
EndFunc
Func _datediff($stype, $sstartdate, $senddate)
Local $asstartdatepart[4]
Local $asstarttimepart[4]
Local $asenddatepart[4]
Local $asendtimepart[4]
Local $itimediff
Local $iyeardiff
Local $imonthdiff
Local $istarttimeinsecs
Local $iendtimeinsecs
Local $adaysdiff
$stype = StringLeft($stype, 1)
If StringInStr("d,m,y,w,h,n,s", $stype) = 0 OR $stype = "" Then
SetError(1)
Return (0)
EndIf
If NOT _dateisvalid($sstartdate) Then
SetError(2)
Return (0)
EndIf
If NOT _dateisvalid($senddate) Then
SetError(3)
Return (0)
EndIf
_datetimesplit($sstartdate, $asstartdatepart, $asstarttimepart)
_datetimesplit($senddate, $asenddatepart, $asendtimepart)
$adaysdiff = _datetodayvalue($asenddatepart[1], $asenddatepart[2], $asenddatepart[3]) - _datetodayvalue($asstartdatepart[1], $asstartdatepart[2], $asstartdatepart[3])
If $asstarttimepart[0] > 1 AND $asendtimepart[0] > 1 Then
$istarttimeinsecs = $asstarttimepart[1] * 3600 + $asstarttimepart[2] * 60 + $asstarttimepart[3]
$iendtimeinsecs = $asendtimepart[1] * 3600 + $asendtimepart[2] * 60 + $asendtimepart[3]
$itimediff = $iendtimeinsecs - $istarttimeinsecs
If $itimediff < 0 Then
$adaysdiff = $adaysdiff - 1
$itimediff = $itimediff + 24 * 60 * 60
EndIf
Else
$itimediff = 0
EndIf
Select
Case $stype = "d"
Return ($adaysdiff)
Case $stype = "m"
$iyeardiff = $asenddatepart[1] - $asstartdatepart[1]
$imonthdiff = $asenddatepart[2] - $asstartdatepart[2] + $iyeardiff * 12
If $asenddatepart[3] < $asstartdatepart[3] Then $imonthdiff = $imonthdiff - 1
$istarttimeinsecs = $asstarttimepart[1] * 3600 + $asstarttimepart[2] * 60 + $asstarttimepart[3]
$iendtimeinsecs = $asendtimepart[1] * 3600 + $asendtimepart[2] * 60 + $asendtimepart[3]
$itimediff = $iendtimeinsecs - $istarttimeinsecs
If $asenddatepart[3] = $asstartdatepart[3] AND $itimediff < 0 Then $imonthdiff = $imonthdiff - 1
Return ($imonthdiff)
Case $stype = "y"
$iyeardiff = $asenddatepart[1] - $asstartdatepart[1]
If $asenddatepart[2] < $asstartdatepart[2] Then $iyeardiff = $iyeardiff - 1
If $asenddatepart[2] = $asstartdatepart[2] AND $asenddatepart[3] < $asstartdatepart[3] Then $iyeardiff = $iyeardiff - 1
$istarttimeinsecs = $asstarttimepart[1] * 3600 + $asstarttimepart[2] * 60 + $asstarttimepart[3]
$iendtimeinsecs = $asendtimepart[1] * 3600 + $asendtimepart[2] * 60 + $asendtimepart[3]
$itimediff = $iendtimeinsecs - $istarttimeinsecs
If $asenddatepart[2] = $asstartdatepart[2] AND $asenddatepart[3] = $asstartdatepart[3] AND $itimediff < 0 Then $iyeardiff = $iyeardiff - 1
Return ($iyeardiff)
Case $stype = "w"
Return (Int($adaysdiff / 7))
Case $stype = "h"
Return ($adaysdiff * 24 + Int($itimediff / 3600))
Case $stype = "n"
Return ($adaysdiff * 24 * 60 + Int($itimediff / 60))
Case $stype = "s"
Return ($adaysdiff * 24 * 60 * 60 + $itimediff)
EndSelect
EndFunc
Func _dateisvalid($sdate)
Local $asdatepart[4]
Local $astimepart[4]
Local $inumdays
$inumdays = "31,28,31,30,31,30,31,31,30,31,30,31"
$inumdays = StringSplit($inumdays, ",")
_datetimesplit($sdate, $asdatepart, $astimepart)
If $asdatepart[0] <> 3 Then
Return (0)
EndIf
If _dateisleapyear($asdatepart[1]) Then $inumdays[2] = 29
If $asdatepart[1] < 1000 OR $asdatepart[1] > 2999 Then Return (0)
If $asdatepart[2] < 1 OR $asdatepart[2] > 12 Then Return (0)
If $asdatepart[3] < 1 OR $asdatepart[3] > $inumdays[$asdatepart[2]] Then Return (0)
If $astimepart[0] < 1 Then Return (1)
If $astimepart[0] < 2 Then Return (0)
If $astimepart[1] < 0 OR $astimepart[1] > 23 Then Return (0)
If $astimepart[2] < 0 OR $astimepart[2] > 59 Then Return (0)
If $astimepart[3] < 0 OR $astimepart[3] > 59 Then Return (0)
Return (1)
EndFunc
Func _datetimesplit($sdate, ByRef $asdatepart, ByRef $itimepart)
Local $sdatetime
Local $x
$sdatetime = StringSplit($sdate, " T")
If $sdatetime[0] > 0 Then $asdatepart = StringSplit($sdatetime[1], "/-.")
If $sdatetime[0] > 1 Then
$itimepart = StringSplit($sdatetime[2], ":")
If UBound($itimepart) < 4 Then ReDim $itimepart[4]
Else
Dim $itimepart[4]
EndIf
If UBound($asdatepart) < 4 Then ReDim $asdatepart[4]
For $x = 1 To 3
$asdatepart[$x] = Number($asdatepart[$x])
$itimepart[$x] = Number($itimepart[$x])
Next
Return (1)
EndFunc
Func _datetodayofweek($iyear, $imonth, $iday)
Local $i_afactor
Local $i_yfactor
Local $i_mfactor
Local $i_dfactor
If NOT _dateisvalid($iyear & "/" & $imonth & "/" & $iday) Then
SetError(1)
Return ("")
EndIf
$i_afactor = Int((14 - $imonth) / 12)
$i_yfactor = $iyear - $i_afactor
$i_mfactor = $imonth + (12 * $i_afactor) - 2
$i_dfactor = Mod($iday + $i_yfactor + Int($i_yfactor / 4) - Int($i_yfactor / 100) + Int($i_yfactor / 400) + Int((31 * $i_mfactor) / 12), 7)
Return ($i_dfactor + 1)
EndFunc
Func _datedayofweek($idaynum, $ishort = 0)
Local $adayofweek[8]
$adayofweek[1] = "Sunday"
$adayofweek[2] = "Monday"
$adayofweek[3] = "Tuesday"
$adayofweek[4] = "Wednesday"
$adayofweek[5] = "Thursday"
$adayofweek[6] = "Friday"
$adayofweek[7] = "Saturday"
Select
Case NOT StringIsInt($idaynum) OR NOT StringIsInt($ishort)
SetError(1)
Return ""
Case $idaynum < 1 OR $idaynum > 7
SetError(1)
Return ""
Case Else
Select
Case $ishort = 0
Return $adayofweek[$idaynum]
Case $ishort = 1
Return StringLeft($adayofweek[$idaynum], 3)
Case Else
SetError(1)
Return ""
EndSelect
EndSelect
EndFunc
Func _datemonthofyear($imonthnum, $ishort)
Local $amonthofyear[13]
$amonthofyear[1] = "January"
$amonthofyear[2] = "February"
$amonthofyear[3] = "March"
$amonthofyear[4] = "April"
$amonthofyear[5] = "May"
$amonthofyear[6] = "June"
$amonthofyear[7] = "July"
$amonthofyear[8] = "August"
$amonthofyear[9] = "September"
$amonthofyear[10] = "October"
$amonthofyear[11] = "November"
$amonthofyear[12] = "December"
Select
Case NOT StringIsInt($imonthnum) OR NOT StringIsInt($ishort)
SetError(1)
Return ""
Case $imonthnum < 1 OR $imonthnum > 12
SetError(1)
Return ""
Case Else
Select
Case $ishort = 0
Return $amonthofyear[$imonthnum]
Case $ishort = 1
Return StringLeft($amonthofyear[$imonthnum], 3)
Case Else
SetError(1)
Return ""
EndSelect
EndSelect
EndFunc
Func _datetodayvalue($iyear, $imonth, $iday)
Local $i_afactor
Local $i_bfactor
Local $i_cfactor
Local $i_efactor
Local $i_ffactor
Local $ijuliandate
If NOT _dateisvalid(StringFormat("%04d/%02d/%02d", $iyear, $imonth, $iday)) Then
SetError(1)
Return ("")
EndIf
If $imonth < 3 Then
$imonth = $imonth + 12
$iyear = $iyear - 1
EndIf
$i_afactor = Int($iyear / 100)
$i_bfactor = Int($i_afactor / 4)
$i_cfactor = 2 - $i_afactor + $i_bfactor
$i_efactor = Int(1461 * ($iyear + 4716) / 4)
$i_ffactor = Int(153 * ($imonth + 1) / 5)
$ijuliandate = $i_cfactor + $iday + $i_efactor + $i_ffactor - 1524.5
Return ($ijuliandate)
EndFunc
Func _dateisleapyear($iyear)
If StringIsInt($iyear) Then
Select
Case Mod($iyear, 4) = 0 AND Mod($iyear, 100) <> 0
Return 1
Case Mod($iyear, 400) = 0
Return 1
Case Else
Return 0
EndSelect
Else
SetError(1)
Return 0
EndIf
EndFunc