Need help adding a "Kill Switch" - autoit

I am writing a code in AutoIt, but need help with a kill switch to stop any processes that I accidently started.
Below is the example of the code that I started that I need a kill switch added to it.
HotKeySet('{PGDN}', 'Intro')
HotKeySet('{F3}', 'ENTgac')
HotKeySet('{F4}', 'LockedENT')
HotKeySet('{F5}', 'VDI')
HotKeySet('{F6}', 'SecurityHold')
HotKeySet('{F7}', 'Printer')
HotKeySet('{F9}', 'AllThingsZ')
HotKeySet('{F10}', 'Bitlocker')
HotKeySet('{F11}', 'Chrome')
While 1
Sleep(50)
WEnd
Func Intro ()
Send('Username: ' & #CRLF)
Send('Computer name: ' & #CRLF)
Send('R' & #CRLF)
Send('Callback number: ' & #CRLF)
Send('Teleworking: ')
EndFunc
Func ENTgac ()
Send("User unable to login and receiving error: 'Must Use Windows Hello error'" & #CRLF)
Send('Had user moved into Pending OU for No Valid Card' & #CRLF)
Send('Had allownongac pushed to INSERT CPU NAME' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func LockedENT ()
Send('Confirmed account lock through cmd > Account Active: Locked' & #CRLF)
Send('Unlocked in NIQ, advised user to login' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func AllThingsZ ()
Send('In Zscaler Updated Policy, Updated App, Clear Logs, Repair App, Restart Service' & #CRLF)
EndFunc
Func Bitlocker ()
Send('User was prompted for Bitlocker Recovery Key' & #CRLF)
Send('Verified user' & #CRLF)
Send('Recited Bitlocker Recovery Key to user' & #CRLF)
Send('Confirmed user was able to login')
EndFunc
Func VDI ()
Send('Guided user through obtaining an secureauth otp code: otp.gsa.gov' & #CRLF)
Send('Guided user through logging into vdi.anywhere.gsa.gov and selecting Light Version for web access' & #CRLF)
Send('User was successfully able to open Standard Desktop')
EndFunc
Func Chrome ()
Send('Made sure Google Chrome was up to date' & #CRLF)
Send('Cleared cookies/cache/history (Settings > Privacy and Security > Clear Browsing Data > Time Range (All Time) > Clear Data)')
EndFunc
Func SecurityHold ()
Send('Provided user with RISSO group email address to contact for approval: risso#gsa.gov' & #CRLF)
Send('User was put in a Security Hold due to failure to complete ROB' & #CRLF)
Send('Submitted Re-Enable request for the user: Enter RITM' & #CRLF)
Send('Submitted Security Compliance Training on users behalf: Enter RITM')
EndFunc
Func Printer ()
Send('Remoted in COMPUTER NAME via BigFix' & #CRLF)
Send('Pressed the “Windows” and “R” keys at the same time' & #CRLF)
Send('Ran printer server by location listed in KB0026350' & #CRLF)
Send('Connected to printer' & #CRLF)
Send('Confirmed test page printed successfully')
EndFunc
Thank you again for any assistance provided. I will provide any information that is needed as quickly as I can.
I have attempted to add like a "Terminate" like below:
Func Terminate()
Exit
;EndSwitch
EndFunc ;==>Terminate
But when I attempt to run it, it does not work

Related

Chilkat: $oImap.ListMailboxes - return "Null object"

I try to use IMAP object from Chilkat AcitveX component.
$oImap.Login($sImapUserName, $sImapPassword)
ConsoleWrite(#ScriptLineNumber & ' LOGIN: ' &$oImap.LastErrorText & #CRLF)
Returns:
Login:
DllDate: Sep 28 2020
ChilkatVersion: 9.5.0.84
UnlockPrefix: ******************
Architecture: Little Endian; 32-bit
Language: ActiveX
VerboseLogging: 0
loginX:
greeting: * OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot (Debian) ready.
authenticateLogin:
loginImap:
ConnectionType: Unencrypted TCP/IP
--loginImap
isOK:
serverResponse: aaab OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY LITERAL+ NOTIFY SPECIAL-USE QUOTA] Logged in
--isOK
--authenticateLogin
--loginX
Success.
--Login
I use this snippet:
Local $s_refName = ''
Local $s_wildcardedMailbox = '*'
Local $oMBoxes = $oImap.ListMailboxes($s_refName, $s_wildcardedMailbox)
ConsoleWrite(#ScriptLineNumber & ' ' &$oImap.LastErrorText & #CRLF)
Returns:
ListMailboxes:
DllDate: Sep 28 2020
ChilkatVersion: 9.5.0.84
UnlockPrefix: *****
Architecture: Little Endian; 32-bit
Language: ActiveX
VerboseLogging: 0
listMailboxes:
bSubscribedOnly: 0
reference:
mailbox: *
Escaping quotes and backslashes in mailbox name...
utf7EncodedMailboxPath: *
isOK:
serverResponse: aaac OK List completed (0.016 + 0.000 + 0.015 secs).
--isOK
Success.
--listMailboxes
Success.
--ListMailboxes
Problem description:
I try to get Listboxes collection object but I do not get properly collections of objects.
If I check it like this:
ConsoleWrite('! ' & IsObj($oMBoxes) & #CRLF)
RESULT: ! 0
ConsoleWrite('! ' & VarGetType($oMBoxes) & #CRLF)
RESULT: ! Object
ConsoleWrite('! ' & $oMBoxes.Count)
RESULT: from COM Error Handler I get:
err.number is: 0x00000004
err.windescription: NULL Pointer assignment
eventually using diffrent version of AutoIt I get:
err.number is: 0x00000003
err.windescription: Object Invoke failed
Question:
Any idea of the cause of the problem?
Registering object by using:
regsvr32 ChilkatAx-9.5.0-win32.dll
Fix this issue.

RF-AutoIT: Cant upload files in Chrome

I am trying to create a common exe for 3 browser based file upload using below code.
IE (Choose File to Upload),
Chrome (Open),
Firefox (File Upload)
This is working for IE but not for Chrome and FireFox. There is no error but its not showing given file along with path.
I will be using this .exe in my Robot Framework script.
#include <MsgBoxConstants.au3>
SelectWindowBasedOnTitle()
Func SelectWindowBasedOnTitle()
$winList = WinList()
$wTitle = CheckWindows($winList)
IF $wTitle == "Choose File to Upload" Then
IE()
ElseIf $wTitle == "Open" Then
Chrome()
Else
FireFox()
EndIf
EndFunc
Func CheckWindows($aArray)
For $i = 1 To Ubound($aArray) - 1
If WinActive($aArray[$i][1]) Then $wTitle= $aArray[$i][0] ;MsgBox(0, "Window Check", $aArray[$i][0] & " is active.")
Next
Return $wTitle
EndFunc
Func Example()
$wText = WinGetText("[ACTIVE]")
EndFunc
Func IE()
ControlFocus("Choose File to Upload","","Edit1")
ControlSetText("Choose File to Upload","","Edit1",$CmdLine[1])
ControlClick("Choose File to Upload","","Button1")
EndFunc
Func Chrome()
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlClick("Open","","Button1")
EndFunc
Func FireFox()
ControlFocus("File Upload","","Edit1")
ControlSetText("File Upload","","Edit1",$CmdLine[1])
ControlClick("File Upload","","Button1")
EndFunc
This way i am using in my Robot script. Could you please help me understand is there a way to automate
${FileInfo} ${CURDIR}\\Xpaths.txt
${AutoIT} ${CURDIR}\\BrowserBasedWindowSelection.exe
Run Process ${AutoIT} ${FileInfo}

AutoIt Firefox _FFClick doesn't work on button? (FF.au3)

Using the firefox plugin ("ff-au3") for AutoIt, how do I click a button?
Here is the HTML of the item I'd like to click:
<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
And here is the code snippet to click the button:
;Click the "Log In" button, id is "login-form-submit"
_FFClick("login-form-submit", "id")
At this point, my script is already connected to firefox, already on the page I need, and everything else works (except for this click part!)
Here is the error I get back:
_FFClick ==> No match: $sElement: FFau3.WCD.getElementById('login-form-submit')
Also, this works when I manually run it on the page using a javascript console:
document.getElementById("login-form-submit")
And here is the API for the plugin: http://english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFClick.php
Anyone see anything I'm doing wrong?
Versions:
Firefox 44.0.1
AutoIt v3.3.14.2
FF V0.6.0.1b-15.au3 (Firefox plugin)
MozRepl v.1.1.2
SciTE-Lite v. 3.5.4
Well this didn't get much traffic but I found the solution! Pretty simple... I disconnected from firefox before executing the click!
When using firefox, you first need to open the firefox exe with the "Run" command, then you need to connect to firefox using the "_FFConnect" command. Next you can start clicking elements. Once you're done, disconnect from firefox using the "ProcessClose" command. The problem I was running into was I connected to firefox, then disconnected immediately, then I tried clicking. So, I made sure I disconnected after I did the clicking...
Working solution: myScript.au3 (See the "LogIn" function at the bottom)
#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <EventLog.au3>
#include <FF V0.6.0.1b-15.au3> ;FireFox
OpenLog()
OpenFirefox()
ConnectToFirefox()
LogIn()
; ////////////////////////////////////////////////////
; Configure the Log
; ////////////////////////////////////////////////////
Func OpenLog()
Global $log = FileOpen("K:\Log.txt", 2)
; Check if file opened for reading OK
If $log == -1 Then
FileWrite($log,"[ERROR] Could not open log file." & #CRLF)
MsgBox(0, "Error", "Unable to open log file.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened log file successfully." & #CRLF)
EndIf
EndFunc
; ////////////////////////////////////////////////////
; Open Firefox
; ////////////////////////////////////////////////////
Func OpenFirefox()
;Run Firefox in Maximized
Global $ffPid = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe","",#SW_MAXIMIZE)
; Check if firefox was opened OK
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open firefox." & #CRLF)
MsgBox(0, "Error", "Could not open firefox.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Firefox opened successfully." & #CRLF)
EndIf
;Wait 10 seconds for Firefox to open
$result = WinWait("[CLASS:MozillaWindowClass]","",10)
; Check if file opened for reading OK
If $result == 0 Then
FileWrite($log,"[ERROR] Unable to open firefox class." & #CRLF)
MsgBox(0, "Error", "Unable to open firefox class.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened firefox class successfully." & #CRLF)
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Connect To Firefox
; ////////////////////////////////////////////////////
Func ConnectToFirefox()
; trying to connect to a running FireFox with MozRepl on
If _FFConnect(Default, Default, 3000) Then
FileWrite($log,"[INFO] Connected to Firefox." & #CRLF)
Else
FileWrite($log,"[ERROR] Can't connect to FireFox!" & #CRLF)
MsgBox(64, "", "Can't connect to FireFox!")
EndIf
;Wait for 2 seconds after opening
Sleep(2000)
EndFunc
; ////////////////////////////////////////////////////
; Log into page
; ////////////////////////////////////////////////////
Func LogIn()
;Load Login Page
_FFOpenURL("http://localhost/login.jsp")
Sleep(2000)
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not open URL." & #CRLF)
MsgBox(0, "Error", "Could not open URL.", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Opened URL successfully." & #CRLF)
EndIf
Sleep(2000)
;Click the "Log In" button, id is "login-form-submit"
;<input accesskey="s" class="aui-button" id="login-form-submit" name="login" title="Press Alt+s to submit this form" type="submit" value="Log In">
_FFClick("login-form-submit", "id")
If #error <> 0 Then
FileWrite($log,"[ERROR] Could not click login button." & #CRLF)
MsgBox(0, "Error", "Could not click login button:", [ timeout = 0])
Exit
Else
FileWrite($log,"[INFO] Found and clicked login button successfully." & #CRLF)
EndIf
EndFunc

Get and execute command in HTA

I'm new in scripting. I need the code to receive some arguments and execute it in hidden cmd in HTA.
the command to execute is
netsh wlan set hosted mode=allow ssid="name" key="pwd"
Here i want to get "name" and "pwd" from submit box and execute the above command in hidden hta.
I made it, but not working properly. See
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub StartProgram
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value "key=" & T2.value
iReturn=objShell.Run(cmdarg, 0, True)
If iReturn = 0 Then
MsgBox "Success"
Else
MsgBox "Cannot Start"
End If
TraceOut.innerHTML= strOut
end sub
</script>
I don't know if this is the whole problem, but at the very least:
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value "key=" & T2.value
should be
cmdarg="%comspec% /c netsh wlan set hosted mode=allow ssid=" & T1.value & " key=" & T2.value
In other words, you left an ampersand out after T1.value, and left a space out before key=.

Autoit change name on window and use it in WinActivate

I have a function that starts some files and then change their names to their ids:
Global $PID2 = Run("java " & $chosen & ' -jar "spigot-1.6.2-R0.1.jar"', "E:\Spill\Alle spill\Minecraft\Bungee Servers\Hub", $Hide)
WinWaitActive("C:\Windows\system32\java.exe")
WinSetTitle("C:\Windows\system32\java.exe","",$PID2)
Global $PID3 =Run("java " & $chosen & ' -jar "spigot-1.6.2-R0.1.jar"', "E:\Spill\Alle spill\Minecraft\Bungee Servers\Survival", $Hide)
WinWaitActive("C:\Windows\system32\java.exe")
WinSetTitle("C:\Windows\system32\java.exe","",$PID3)
Global $PID4 =Run("java " & $chosen & ' -jar "spigot-1.6.2-R0.1.jar"', "E:\Spill\Alle spill\Minecraft\Bungee Servers\KnarWorld", $Hide)
WinWaitActive("C:\Windows\system32\java.exe")
WinSetTitle("C:\Windows\system32\java.exe","",$PID4)
Global $PID5 =Run("java " & $chosen & ' -jar "spigot-1.6.2-R0.1.jar"', "E:\Spill\Alle spill\Minecraft\Bungee Servers\Plotworld", $Hide)
WinWaitActive("C:\Windows\system32\java.exe")
WinSetTitle("C:\Windows\system32\java.exe","",$PID5)
Global $PID1 =Run("java " & $chosen & ' -jar "BungeeCord.jar"', 'E:\Spill\Alle spill\Minecraft\bungee', $Hide)
WinWaitActive("C:\Windows\system32\java.exe")
WinSetTitle("C:\Windows\system32\java.exe","",$PID1)
I also have a function to stop the files:
WinActivate($PID1)
Send("end {ENTER}")
WinActivate($PID2)
Send("stop{ENTER}")
WinActivate($PID3)
Send("stop{ENTER}")
WinActivate($PID4)
Send("stop{ENTER}")
WinActivate($PID5)
Send("stop{ENTER}")
The problem is on the second function that instead of finding the ids and sending the wanted commands one by one, it starts spamming in whatever window is active. How can I make it run once and stop, but still work if I trigger it again?
The whole code: http://pastebin.com/U8XBk4HE
For these kind of tasks there are two functions:
SendKeepActive(...) to make AutoIt to attempt to reset the active window in between each simulated keystroke from Send().
ControlSend(...) to send keystrokes to a specific window independently of it being active.
Maybe you should put a WinWaitActive to make it wait:
WinActivate($PID1)
WinWaitActive($PID1)
Send("end {ENTER}")

Resources