Autoit - limiting the number of execution - user-interface

I don't know if it's possible cuz i couldn't find anywhere.
I have created a GUI with some buttons to start things.
I'm just wondering if it is possible to:
limit the number of openings of the GUI
limit the number of executions with the buttons
limit the time range so that after certain point, u can't use it
Global $explain = "help~~"
#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
Has anyone tried this?
Will it require intense coding?
Could you provide a sample if it isn't too bad

Good afternoon Pita,
Yup! It's all definitely possible to do! There's multiple ways to do so, I'll try to name a few.
A good way for you to manage these requests, would be to make a properties file to manage everything. Take a look at my example below!
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 & "\TestProgram\properties.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 " & $newLimit & " 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 " & $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" & #CRLF)
; Sets the expiration date to a week (7 days) from the initial launch date.
FileWrite($fileHandle, #MON & "/" & (#MDAY + 7) & "/" & #YEAR & #CRLF)
; Sets the button limit for the login button to 3.
FileWrite($fileHandle, "3" & #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 " & $newButtonLimit & " 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
Upon launching the program, a property file is generated and stored in the appdata on the users computer.
On windows: Press Win+R and type %appdata%. If you left the example the same, there will be a folder called "TestProgram", if you changed the name, it will be whatever you called it. Inside of this folder, there will be the properties.txt file (Again, unless you changed the name).
I have made some comments in the example code to help explain what I did, but I'm not fantastic at explaining things so please let me know if you need some more help.
P.S. If you do use this method, I strongly suggest encrypting (Using Crypt maybe?) the properties file to make it a little less editable and designing some way to tell if the user deleted the file.
I hope this helps!,
Tim

Related

qb64 unable to load image using _putimage, I&

I'm trying to load an image for the title of my game instead of ASCII for my title, whenever I try to run it, it gives me an error.
I've tried the multiple ways QB64 suggest you load images, but it says the same thing
it says that _putimage is an illegal command
menu:
CLS
PRINT
i& = _LOADIMAGE("FOrest.jpg")
_PUTIMAGE , i&
PRINT ""
PRINT "What Will Your Heros Name be?:";
Name$ = Ask$(5, 1, CSRLIN, POS(0), 11, 0)
CLS
check_1% = 0 'placeholder for debuggingg
COLOR 15, 0
PRINT Name$ + "How Old will Your Hero be?: ";: age% = VAL(Ask$(3, 0, CSRLIN, POS(0), 15, 0))
'INPUT "", age%
I expect that it load my image:
Code to load forest.jpg:
SCREEN _NEWIMAGE(640, 480, 32)
CLS , _RGB(0, 255, 0)
i& = _LOADIMAGE("FOREST.JPG")
IF i& = -1 THEN PRINT "invalid image": END
_PUTIMAGE (0, 0), i&, 0
END

How can i style my GUI as Aero Glass GUI with AutoIt?

How can i get the Aero Glass effect for my Autoit GUI?
I am playing a bit with AutoIt to increase my knowledge about GUI stuff. Usually i just create scripts without the usage of a GUI, but i would like to have a nice looking areo glass GUI when i just start to work with.
I already experiment with WinSetTrans but this is not exactly what i want. It should look more like the image below.
My current code is:
#include <GUIConstants.au3>
$iWidthGui = 450
$iHeightGui = 300
$hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
$cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW )
WinSetTrans($hGui, "", 180)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
Is it possible with Autoit? How can i do that?
Yes it is possible. This should work at least for Windows 7. I couldn't test the script on a Windows 10 machine.
Improved code:
#include-once
#include <GUIConstants.au3>
Global $iWidthGui = 450
Global $iHeightGui = 300
Global $hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
Global $cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW, $hGui )
Func _aeroGlassEffect( $hWnd, $iLeft = #DesktopWidth, $iRight = #DesktopWidth, $iTop = #DesktopWidth, $iBottom = #DesktopWidth )
$hStruct = DllStructCreate( 'int left; int right; int height; int bottom;' )
DllStructSetData( $hStruct, 'left', $iLeft )
DllStructSetData( $hStruct, 'right', $iRight )
DllStructSetData( $hStruct, 'height', $iTop )
DllStructSetData( $hStruct, 'bottom', $iBottom )
GUISetBkColor( '0x000000' )
Return DllCall( 'dwmapi.dll', 'int', 'DwmExtendFrameIntoClientArea', 'hWnd', $hWnd, 'ptr', DllStructGetPtr( $hStruct ) )
EndFunc
_aeroGlassEffect( $hGui )
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
I switched WinSetTrans() for _aeroGlassEffect(). You can change the function parameters $iLeft, $iRight, $iTop, $iBottom.

Button at the end of array in AutoIT

I am working on a program that pulls data from AD via a linked table in SQL and lets the user copy an email address to the clipboard. I am using an array to dynamically display a button beside each row. The problem is that, when I try and put labels or buttons inside the for loop, they don't show up. Is it just that I'm doing it wrong. My code is as follows:
#include <GUIConstantsEx.au3>
#include <mssql.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
global $title = "E-Mail address lookup"
global $sqlCon = _MSSQL_Con("server", "user", "Directory3=", "password")
global $name = InputBox($title,"Please type the name of the person you wish to find")
global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'")
if StringLen(StringStripWS($name,3)) < 1 then
MsgBox(0, $title, "Name cannot be empty")
Else
Global $ControlID = GUICreate($title, 530, 500)
GUISetState(#SW_SHOW)
Local $iOldOpt = Opt("GUICoordMode", 2)
GUICtrlCreateLabel(" ", 0, 0, 80)
GUICtrlCreateLabel("E-Mail Address", 20, -1, 100)
GUICtrlCreateLabel("Name", 20, -1, 50)
GUICtrlCreateLabel("Department", 20, -1, 100)
GUICtrlCreateLabel("Telephone Number", 20, -1, 200)
for $i = 1 To UBound($result) Step 1
GUICtrlCreateButton("Copy", 0, $i, 30, 20)
Next
GUISetState()
While 1
Global $Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
EndSwitch
WEnd
EndIf
I would have expected one button to show up on a new line on every iteration of the loop
I recommend to use another mode:
#include <GUIConstantsEx.au3>
;~ #include <mssql.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
Global $title = "E-Mail address lookup"
;~ global $sqlCon = _MSSQL_Con("server", "user", "Directory3=", "password")
;~ global $name = InputBox($title,"Please type the name of the person you wish to find")
;~ global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'")
Global $result = StringSplit('1,2,3,4,5,6,7,8', ',')
;~ if StringLen(StringStripWS($name,3)) < 1 then
;~ MsgBox(0, $title, "Name cannot be empty")
;~ Else
;~ _ArrayDisplay($result)
Global $ControlID = GUICreate($title, 530, 500)
;~ Local $iOldOpt = Opt("GUICoordMode", 2)
GUICtrlCreateLabel(" ", 0, 0, 80)
GUICtrlCreateLabel("E-Mail Address", 20, -1, 100)
GUICtrlCreateLabel("Name", 20, -1, 50)
GUICtrlCreateLabel("Department", 20, -1, 100)
GUICtrlCreateLabel("Telephone Number", 20, -1, 200)
For $i = 1 To UBound($result) - 1
GUICtrlCreateButton("Copy", 20, $i * 20, 350, 20)
Next
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
EndSwitch
WEnd

Replicate text from AutoIt form to Notepad

I am using this AutoIt code to send text to Notepad on the press of a button:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form = GUICreate("Replicate text to notepad", 615, 50, 190, 122)
$Input = GUICtrlCreateInput("Placeholder text", 0, 0, 609, 21)
$Button = GUICtrlCreateButton("Send to notepad", 0, 24, 609, 25)
GUISetState(#SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
Example(GUICtrlRead($Input))
EndSwitch
WEnd
Func Example($text)
Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
ControlSend($hWnd, "", "Edit1", $text)
EndFunc
It is working great. But now I want to send keystrokes as soon as I press them. Is there something like OnKeyDown in AutoIt? So I don't have to press the send button to send it to Notepad every time I type a character.
This is how I would do it.
Work pretty neat!
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Run("notepad.exe")
Global $hWnd = WinWait("[CLASS:Notepad]", "", 10)
$Form = GUICreate("Replicate text to notepad", 615, 50, 190, 122)
$Input = GUICtrlCreateInput("Placeholder text", 0, 0, 609, 21)
$Button = GUICtrlCreateButton("Send to notepad", 0, 24, 609, 25)
GUISetState(#SW_SHOW)
$OldText = ""
While 1
$nMsg = GUIGetMsg()
$NewText = GUICtrlRead($Input)
If $OldText <> $NewText Then
$OldText = $NewText
Example($NewText)
EndIf
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
Example(GUICtrlRead($Input))
EndSwitch
WEnd
Func Example($text)
ControlSetText($hWnd, "", "Edit1", $text)
EndFunc

rdp session terminal server sendKeys

I don't know how can I send "windows + r" in order to open the small window (execute ...) to the terminal serveur.. Anybody can help me ? I tried Send("#r") but it doesn't work
$host = "" ; <---- IP
$hGUI = GUICreate("Terminal Serveur", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2")
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ; <--- Username
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = "" ; <--- Password
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()
$oShel = ObjCreate("shell.application")
$oShel_Ctrl = GUICtrlCreateObj($oShel, 64, 44, 800, 600)
GUICtrlSetStyle($oShel_Ctrl , $WS_VISIBLE)
GUISetState(#SW_SHOW, $hGUI)
Send ("#r") !!!!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$oRDP.Disconnect()
Exit
EndSwitch
Did u try to do it with ShellExecute instead of opening the window first?
//Edit I just saw tht u asked the question before and tht u want to run the command at the other computer

Resources