Autoit — ограничение количества выполнений

#user-interface #time #limit #autoit

#пользовательский интерфейс #время #ограничение #autoit

Вопрос:

Я не знаю, возможно ли это, потому что я нигде не мог найти. Я создал графический интерфейс с несколькими кнопками для запуска.

Мне просто интересно, возможно ли:

  1. ограничить количество открытий графического интерфейса
  2. ограничьте количество выполнений с помощью кнопок
  3. ограничьте временной диапазон, чтобы после определенного момента вы не могли его использовать

Глобальный $explain = «справка ~~»

 #include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $explain = "hmmm"
Global $Form1 = GUICreate("Yay", 328, 157)
Global $Label1 = GUICtrlCreateLabel("ID", 12, 14, 67, 20)
Global $Label2 = GUICtrlCreateLabel("Password", 12, 44, 67, 20)
Global $Label3 = GUICtrlCreateLabel("hello world", 225, 14, 90, 20)
Global $Input1 = GUICtrlCreateInput("", 76, 10, 105, 24)
Global $Input2 = GUICtrlCreateInput("", 76, 40, 105, 24, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
Global $Input3 = GUICtrlCreateInput("", 228, 40, 70, 24)
Global $Button1 = GUICtrlCreateButton("Log In", 76, 69, 105, 30)
Global $Button2 = GUICtrlCreateButton("Connect", 212, 69, 100, 30)
Global $Checkbox1 = GUICtrlCreateCheckbox("hmm", 240, 113, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("hmm2", 240, 134, 97, 17)

Global $Group1 = GUICtrlCreateGroup("", 5, -5, 190, 110)
Global $Edit1 = GUICtrlCreateEdit("", 5, 110, 228, 100)
GUICtrlSetData(-1, $explain)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Checkbox1
        If (GUICtrlRead($Checkbox1) = $GUI_CHECKED) Then
            Global $hmm = 1
        EndIf
    Case $Checkbox2
        If (GUICtrlRead($Checkbox2) = $GUI_CHECKED) Then
            Global $hmm2 = 0
        EndIf
    Case $Button1
        Global $id = GUICtrlRead($Input1)
        Global $pass = GUICtrlRead($Input2)
        WinSetState("Yay", "", @SW_MINIMIZE)
        MsgBox(0,"","possible to limit #of Execution?")
    Case $Button2
        Global $exnum = GUICtrlRead($Input3)
        WinSetState("Yay", "", @SW_MINIMIZE)
        MsgBox(0,"","time limit would be nice too! thnx!")
EndSwitch
WEnd
  

Кто-нибудь пробовал это?
Потребует ли это интенсивного кодирования?
Не могли бы вы предоставить образец, если это не так уж плохо

Комментарии:

1. Не могли бы вы уточнить, что должен делать этот скрипт? Что вы имеете в виду под «открытием графического интерфейса»? Число, как часто запускается этот скрипт или сколько экземпляров скрипта может быть запущено одновременно?

Ответ №1:

Добрый день, Pita,

Ага! Все это определенно возможно сделать! Для этого есть несколько способов, я постараюсь назвать несколько.

Хорошим способом управления этими запросами было бы создать файл свойств для управления всем. Взгляните на мой пример ниже!

 Global $explain = "help~~"

#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; =================================================================================================================================================
#include <File.au3>
#Include <Date.au3>

; This is the directory that the temporary file will be stored.
$fileHandle = @AppDataDir amp; "TestProgramproperties.txt"

; Checks to see if the properties file exists
if FileExists($fileHandle) Then
    ; START Check Run Limit
    ; Reads the first value in the properties file. In this example, it's the limit to how many times the program can be launched.
    $runLimit = FileReadLine($fileHandle, 1)
    ; MsgBox(0,"Run Limit", $runLimit)
    ; If the run limit reaches zero (or less than by some glitch), do not launch the program.
    if $runLimit <= 0 Then
        MsgBox(16,"Run Limit Reached", "You have reached the maximum number of launches for this program!")
        Exit
    EndIf
    ; Subtract one from the launch limit.
    $newLimit = $runLimit - 1
    MsgBox(0,"New Run Limit", "You may launch this program " amp; $newLimit amp; " more times!", 3)
    ; Update the properties file.
    _FileWriteToLine($fileHandle, 1, $newLimit, True)
    ; END Check Run Limit

    ; Start CHECK Expiration Date
    $expDate = FileReadLine($fileHandle, 2)
    ; MsgBox(0,"Expiration Date", "This program expires on " amp; $expDate)
    ; Check to see if the expiration date has already passed
    if $expDate < _NowDate() Then
        MsgBox(16,"Program Expired","Your trial period has expired!")
        Exit
    EndIf

    ; END Check expiration date
Else
    ; If the file does not exists, create it and set it up
    $propFile = FileOpen($fileHandle, 10)
    ; Sets the launch limit to 10. Change this value to set the launch limit
    FileWrite($fileHandle, "10" amp; @CRLF)
    ; Sets the expiration date to a week (7 days) from the initial launch date.
    FileWrite($fileHandle, @MON amp; "/" amp; (@MDAY   7) amp; "/" amp; @YEAR amp; @CRLF)
    ; Sets the button limit for the login button to 3.
    FileWrite($fileHandle, "3" amp; @CRLF)
    FileClose($fileHandle)

    #CS
        NOTE: THIS IS JUST FOR DEMONSTRATION PURPOSES! THE USER CAN SIMPLY DELETE THE PROPERTIES FILE
            IN ORDER TO RESET THE VALUES AND CONTINUE USING THE PROGRAM. THIS WAS DESIGNED SIMPLY TO
            GET YOU ON THE RIGHT TRACK.
    #CE
EndIf



; =================================================================================================================================================

Global $explain = "hmmm"
Global $Form1 = GUICreate("Yay", 328, 157)
Global $Label1 = GUICtrlCreateLabel("ID", 12, 14, 67, 20)
Global $Label2 = GUICtrlCreateLabel("Password", 12, 44, 67, 20)
Global $Label3 = GUICtrlCreateLabel("hello world", 225, 14, 90, 20)
Global $Input1 = GUICtrlCreateInput("", 76, 10, 105, 24)
Global $Input2 = GUICtrlCreateInput("", 76, 40, 105, 24, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
Global $Input3 = GUICtrlCreateInput("", 228, 40, 70, 24)
Global $Button1 = GUICtrlCreateButton("Log In", 76, 69, 105, 30)
Global $Button2 = GUICtrlCreateButton("Connect", 212, 69, 100, 30)
Global $Checkbox1 = GUICtrlCreateCheckbox("hmm", 240, 113, 97, 17)
Global $Checkbox2 = GUICtrlCreateCheckbox("hmm2", 240, 134, 97, 17)

Global $Group1 = GUICtrlCreateGroup("", 5, -5, 190, 110)
Global $Edit1 = GUICtrlCreateEdit("", 5, 110, 228, 100)
GUICtrlSetData(-1, $explain)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Checkbox1
        If (GUICtrlRead($Checkbox1) = $GUI_CHECKED) Then
            Global $hmm = 1
        EndIf
    Case $Checkbox2
        If (GUICtrlRead($Checkbox2) = $GUI_CHECKED) Then
            Global $hmm2 = 0
        EndIf
    Case $Button1
        ; START Button Limit ================================================================================================================
        if FileExists($fileHandle) Then
            $buttonLimit = FileReadLine($fileHandle, 3)
            if $buttonLimit <= 0 Then
                MsgBox(16,"Button Limit Reached", "You have reached the maximum number of times you can hit this button!")
            ELSE
                $newButtonLimit = $buttonLimit - 1
                MsgBox(0,"New Run Limit", "You may press this button " amp; $newButtonLimit amp; " more times!", 3)
                _FileWriteToLine($fileHandle, 3, $newButtonLimit, True)

                ; START OLD CODE
                Global $id = GUICtrlRead($Input1)
                Global $pass = GUICtrlRead($Input2)
                ; WinSetState("Yay", "", @SW_MINIMIZE)
                MsgBox(0,"","possible to limit #of Execution?")
                ; END OLD CODE ================================================================================================================

            EndIf
        EndIf
        ; END Button Limit
    Case $Button2
        Global $exnum = GUICtrlRead($Input3)
        WinSetState("Yay", "", @SW_MINIMIZE)
        MsgBox(0,"","time limit would be nice too! thnx!")
EndSwitch
WEnd
  

При запуске программы создается файл свойств, который сохраняется в appdata на компьютере пользователя.

В Windows: нажмите Win R и введите %appdata%. Если вы оставили пример таким же, будет папка с именем «TestProgram», если вы изменили имя, оно будет таким, как вы его назвали. Внутри этой папки будет properties.txt файл (опять же, если вы не изменили имя).

Я сделал несколько комментариев в примере кода, чтобы помочь объяснить, что я сделал, но я не умею объяснять вещи, поэтому, пожалуйста, дайте мне знать, если вам понадобится дополнительная помощь.

PS Если вы используете этот метод, я настоятельно рекомендую зашифровать (возможно, с помощью Crypt?) Файл свойств, Чтобы сделать его немного менее редактируемым и разработать какой-либо способ определить, удалил ли пользователь файл.

Я надеюсь, что это поможет!,

Время