How can i Make any words into Autoit Commands?
This Code Works only if i type a Keyboard Hotkey combination, (but i want to type a word to execute the Autoit code.)
HotKeySet Example:
HotKeySet (“{F1}”, “calc”)
Func calc()
Local $iPID = ShellExecute (“calc.exe”)
EndFunc
Is there a Hotstringset Alternative.
i now in autohotkey you can make any words into Commands.
Autohotkey Languages example:
if i type calc it will execute the Autohotkey code.
:*:calc::
run calc.exe
return
With this you can make any words into Autoit Commands.
Step 1 - You can Download the HotStringSet.zip File Here. (included with the HotString.au3) HotKeySet vs HotStringSet
Step 2 - Unzip it + Copy manually the HotString.au3 to path C:\Program Files (x86)\AutoIt3\Include
Step 3 - Now your are ready to use HotStringSet in any Autoit Script.
You can Type on your keyboard any text, for example in Wordpad : Type calc+Space and it will run the Calculator and if you Type kbc+Space it will replace the text kbc into keyboard control and if you Type pi+Space it will replace the text pi into Symbol pi.
Write this Autoit Code.
#include <HotString.au3>
HotKeySet ('{F1}', 'quit')
HotStringSet('kbc{SPACE}', replace1)
HotStringSet('pi{SPACE}', replace2)
HotStringSet('calc{SPACE}', replace3)
Func quit()
Exit
EndFunc
Func replace1()
;MsgBox(0,'','You did typed kbc! :)')
send ('{BS 4}keyboard control ') ; replace [kbc] into [keyboard control]
EndFunc
Func replace2()
;MsgBox(0,'','You did typed pi! :)')
send ('{BS 3}{ASC 960} ') ; replace [pi] into [symbol p]
EndFunc
Func replace3()
;MsgBox(0,'','You did typed calc! :)')
Local $iPID = ShellExecute ('calc.exe') ; If you type calc it wil run the application calculator.
EndFunc
While 1
Sleep(10)
WEnd
Related
I'd like to include certain script only if it's present. Unfortunately #include is processed before the execution, so I can't make it conditional like this:
If FileExists(#ScriptDir & "\common.au3") Then
#include "common.au3"
EndIf
I tried to use Execute to evaluate the read file in place via Execute(ReadFile(...)). But that seems to only process single statements - I couldn't declare multiple functions for example.
Is there a different way to conditionally include another file?
Probably not a good design choice but if you really need to do somethin like this, try #OnAutoItStartRegister:
#OnAutoItStartRegister "_OnAutoItStart_CreateIncludes"
#include "include_collection.au3"
If IsDeclared("iExample_Common") Then
MsgBox(64, "", "Common.au3 exists")
Else
MsgBox(16, "", "Common.au3 wasnt included")
EndIf
MsgBox(0, "", "Your Script here")
Func _OnAutoItStart_CreateIncludes()
If StringInStr($CmdLineRaw, '-_OnAutoItStart_CreateIncludes', 1) Then Return
If FileExists(#ScriptDir & "\common.au3") And Not StringInStr(FileRead("include_collection.au3"), '#include "common.au3"') Then
FileWrite("include_collection.au3", '#include "common.au3"')
EndIf
$iPID = Run('"' & #AutoItExe & '" ' & $CmdLineRaw & ' -_OnAutoItStart_CreateIncludes', #WorkingDir, Default, 2)
While ProcessExists($iPID)
ConsoleWrite(StdoutRead($iPID))
Sleep(10)
WEnd
Exit
EndFunc ;==>_OnAutoItStart_CreateIncludes
Create an additional empty file "include_collection.au3" as well.
In this example, I created "commons.au3" containing a statement "$iExample_commons = 1234'.
Note: Once the file is included this way, it should not be deleted otherwise your script will fail again. This could probably be overcome too but at some point it will become very messy.
Maybe it's a better Idea to wrap a launcher around your application which will add/remove include lines before startup as needed.
I am a beginner with python. I want to run a whole function in the background (because it can take a while or even fail).
Here is the function:
def backup(str):
command = barman_bin + " backup " + str
log_maif.info("Lancement d'un backup full:")
log_maif.info(command)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()
if p.returncode == 0:
for line in output[0].decode(encoding='utf-8').split('\n'):
log_maif.info(line)
else:
for line in output[0].decode(encoding='utf-8').split('\n'):
log_maif.error(line)
log_maif.info("Fin du backup full")
return output
I want to run this function in the background into a loop :
for host in list_hosts_sans_doublon:
backup(host) # <-- how to run the whole function in background ?
In ksh, I would have written something like backup $host & with backup a function that takes $host as an argument.
What you are looking for is to run the function in a different thread from what I understand. For this you need to use python thread module.
This is how you start a thread:
import threading
def backup(mystring):
print(mystring)
host="hello"
x = threading.Thread(target=backup, [host])
x.start()
Do what ever you want after this and the thread will run separately.
as the title says, here is my code but its not working
; Get the parameter from open file dialog
GUICtrlSetData($locationtxt, FileOpenDialog("Select the program", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3))
; store the value in a variable
$abc = GUICtrlRead($locationtxt)
; Run the program and pass the parameter value
Run("ussf.exe " & $abc )
; If i do it this way, its working but i want the parameter value from the open dialog not fixed
Run("ussf.exe C:\Users\project\ccsetup563.exe")
The second parameter for Run() is the working directory, not an argument for the program. I think you should be using ShellExecute(), or ShellExecuteWait() instead.
I am new to Autoit and tried to do this:
Local $stest = "C:\Program Files (x86)\test\test.exe";
Local $sPath;
runS($stest);
Func runS(String $sPath) {
this.$sPath = $sPath;
If FileExists($stest) {
Run($stest , "", #SW_SHOWMAXIMIZED)
}
}
And get this error:
(6) : ==> Badly formated variable or macro.:
I am just trying to write a parameter as a path in the function...
No lines in AutoIt end with a ";". The ";" is used for commenting in
AutoIt.
If statements must have a “then” statement.
Nothing in AutoIt is opened or closed with the curly braces “{}”.
Most statements are closed with semantic words like EndIf, EndFunc and
Wend.
Here is what your code should look like:
;$g_sTest is global variable because it is being declared outside of a function.
Global $g_sTest = "C:\Program Files (x86)\test\test.exe"
runS($stest)
;$sPath will be a local variable because it is being declared inside of the fuction.
Func runS($sPath)
If FileExists($sPath) Then
Run($sPath, "", #SW_SHOWMAXIMIZED)
EndIf
EndFunc
I am trying to uninstall a program from add or remove programs via an AutoIt script.
*I dont want to uninstall via removing the registry keys.
* I dont want to uninstall via running an uninstaller.
I can open "add remove programs" by a appwiz.cpl command
However I am failing to recognize the correct program name from the list and invoke an uninstall.
All I want to do is recognize my program from the list, for example "Helloworld" and invoke an uninstall.
You can just loop through all your corresponding Registry Values of which your uninstall list in your "Add or remove programs" is made of... And then directly extract the command that you want to execute. I display it in a Message Box in this example, but you could directly compare the DisplayName to "Helloworld" and then execute the UninstallString with Run(...). This is the exact same as your "Add or remove programs" would invoke. It doesn't mean simply removing registry keys. And it doesn't mean just running "any" uninstaller but the proper one, needed to exactly uninstall this very program like clicking the "Uninstall" button in appwiz.cpl will invoke. So to perform what you asked for as a result, this solution works just fine. It does not acutally handle the appwiz.cpl and cycle through the list of programs...
$uninstall_path1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall"
searchUninstallStrings($uninstall_path1)
$uninstall_path2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
searchUninstallStrings($uninstall_path2)
Func searchUninstallStrings($uninstall_path)
$i = 0
While True
$i += 1
Local $entry = RegEnumKey($uninstall_path, $i)
If #error <> 0 Then ExitLoop
$regPath = $uninstall_path & "\" & $entry
$DisplayName = RegRead($regPath, "DisplayName")
If $DisplayName <> "" Then
$message = $DisplayName & #CR
$UninstallString = RegRead($regPath, "UninstallString")
If $UninstallString <> "" Then
$message &= "Uninstall: '" & $UninstallString & "'"
MsgBox(4096, "SubKey #" & $i & ": " & $entry, $message)
EndIf
EndIf
WEnd
EndFunc
Good Luck!
I was able to successfully automate program uninstalls with the following command to open up the Programs and Features control panel menu followed by a series of keystrokes:
Run("C:\Windows\System32\control.exe appwiz.cpl")
WinWait("Programs and Features")
WinActivate("Programs and Features")
Send("ProgramNameHere")
Send("{Enter}")