Autoit change name on window and use it in WinActivate - autoit

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}")

Related

Need help adding a "Kill Switch"

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

Autoit - "possibly used before declaration" and "undeclared global variable" Compile Error

This is my first aproach to AutoIt and my apologies for the basic questions
I have an AutoIt program/code that is made of 2 .au3 files
1 - I would like to ask, how does that files work together (how they can be combined, if this is possbile) or are they supposed to be 2 seperate programs?
2 - When I run AutoIt3_x64, in one of them, I get the error
Line xxxx
Error: Variable used without being declared.
I have run Au3Stripper before compile and I got the followin errors/warning
-> 3 Change(s) made.
>Running AU3Check (3.3.14.5) from:C:\..\AutoIt3 input:C:\..\project.au3
"C:\..\project.au3"(203,110) : warning: $key: possibly used before declaration.
File($CommonFilesDir & "\" & $first_run, $CommonFilesDir & "\" & $first_run & $first_run, $key,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\..\project.au3"(203,110) : error: $key: undeclared global variable.
File($CommonFilesDir & "\" & $first_run, $CommonFilesDir & "\" & $first_run & $first_run, $key,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\..\project.au3"(273,32) : error: server(): undefined function.
$get_table = server()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\..\project.au3 - 2 error(s), 1 warning(s)
!>06:52:51 AU3Check ended. Press F4 to jump to next error.rc:2
+>06:52:51 AutoIt3Wrapper Finished.
What is causing these errors/warning and how can I fix it?
Thank you
EDIT:
Unfortunately, following the link sugestions, I didn't managed to succeed and for sure it's my fault. Th structure of the link exemple is diferente
one of the errors refers to this part of the code
if not FileExists($CommonFilesDir & "\" & $first_run & $first_run) Then
File($CommonFilesDir & "\" & $first_run, $CommonFilesDir & "\" & $first_run & $first_run, $key)
FileWrite($CommonFilesDir & "\" & $reverse_diskid, Get_Table())
FileDelete($CommonFilesDir & "\" & $first_run)
endif
I don't see how can I replicate the link suggestion

Use slash option in R system function

I am trying to use following cmd function inside R
rmdir /q /s myDir
I tried:
system("rmdir /q /s myDir")
but it returns an error:
rmdir: failed to remove '/q': No such file or directory
rmdir: failed to remove '/s': No such file or directory
rmdir: failed to remove 'public_html/croecon.contentio.biz': Directory not empty
How should I use slash option, e.g. /q?
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery("SELECT * FROM Win32_ProcessStartTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & objReceivedEvent.ProcessID)
For Each objItem in colItems
wscript.echo objItem.name & " " & objItem.ProcessID & " " & objItem.CommandLine
Next
Loop
Then type in a command prompt
cscript //nologo C:\folder\MonitorProcessCreation.vbs
This will monitor what starts when you run your command.

unix nohup sqlplus not working

Trying to run all of the sql scripts in one NOHUP command. Below is my code. But, it is not running in nohup mode based on the below. There are no errors either. How do I run all of the below in one NOHUP command??
nohup sqlplus -S /NOLOG << %EOF% > engine_error.log
WHENEVER SQLERROR EXIT 1;
#$Level2/passFile server05
#engine_check.sql $stroke1 $bore1
#engine_start.sql
%EOF% &
When you have a script that must start some background jobs, make a script that starts functions with & and nohup your script.
When your script startit.sh looks like
function f1 {
echo "f1 start"
sleep 2
echo "f1 end"
}
function f2 {
echo "f2 start"
sleep 1
echo "f2 end"
}
function f3 {
echo "f3 start"
sleep 1
cat <<END
f3 start here
more f3
f3 end here
END
echo "f3 end"
}
f1 &
f2
f3 &
call nohup startit.sh.
Try putting this in a script and then nohup the script. The nohup is probably getting confused because of the command.
#!/usr/bin/env
#query.sh
sqlplus -S /NOLOG << %EOF% > engine_error.log
WHENEVER SQLERROR EXIT 1;
#$Level2/passFile server05
#engine_check.sql $stroke1 $bore1
#engine_start.sql
EOF
Then in your shell try doing this
nohup query.sh &
Problem is "&" (or any sign) in same line with EndOfMessage-String.
"EOF &" is not equal to "EOF" -> "inline script" is still waiting for "EOF".
A line with only the defined string after "<<" can finalize the "inline script":

Run many AutoIt script files using a main file (XML, Java, AutoIt or any language)

I'm using AutoIt for testing my application. There are different test cases for that. I will create these test cases as au3 files. Now I want to run all these scripts one after other. That is, a main script which call all sub script files one after other. How can I do that?
In a main AutoIt script (main.au3) you just add:
#include <UDF_function_1.au3>
#include <UDF_function_2.au3>
#include <UDF_function_3.au3>
Func _lanch_all()
; In order to run AutoIt function
_function_1() ; from UDF_function_1.au3
_function_2() ; from UDF_function_2.au3
_function_3() ; from UDF_function_3.au3
Run(PATH_to_script\"script_1.bat") ; In order to run a batch script windows
Run(PATH_to_executable\"script_2.exe") ; In order to run an executable
EndFunc
And for example UDF_function_1.au3 contains:
#include-once
Func _function_1()
ConsoleWrite("Call of _function_1"&#CRLF)
EndFunc
If you don't want to compile these test cases, you just compile the main exe:
Compiled.exe [/ErrorStdOut] [/AutoIt3ExecuteScript file] [params ...]
Execute another script file from a compiled AutoIt3 Script File. Then you don't need to fileinstall another copy of AutoIT3.exe in your compiled file.
#include <File.au3>
$Path = #ScriptDir & 'TestCases\'
$files = _FileListToArray($Path, "*.au3")
For $i = 1 To $files[0]
RunWait(#ScriptFullPath & '/AutoIt3ExecuteScript "' & $Path & $files[$i] & '.au3"')
Next
Just create a master AutoIt program and have this program run the other sub programs. If they are present in .au3 format, simply have the master program include the sub programs via the include keyword:
#include "[path\]filename"
This will allow the master program to call functions of the included sub-program.
#include <File.au3>
$Path = #ScriptDir & 'TestCases\'
$files = _FileListToArray($Path, "*.au3")
For $i = 1 To $files[0]
RunWait(#ScriptFullPath & '/AutoIt3ExecuteScript "' & $Path & $files[$i] & '.au3"')
Next
modified code as follows:
#include <File.au3>
$Path = #ScriptDir & '\TestCases\'
$files = _FileListToArray($Path, "*.au3")
MsgBox(0,"path", $files[0])
For $i = 1 To $files[0]
RunWait(#AutoItExe & " /AutoIt3ExecuteScript "& '"'& $Path & $files[$i] & '"')
Next

Resources