script file not found autohotkey что делать
Script file not found autohotkey что делать
I’m messing with a code that is called upon first time use of my script.
The problem specifically, is using file move on a running script.
After moving the running script followed by reloading it, I get a «Script File Not Found» error, due to the scripts directory being changed.
There is no documentation, or posts I’ve seen related to this issue, and I can not figure out a way to prevent this error/change to the new directory.
I thought SetWorkingDir was what I needed, but it does nothing?
Any help would be great, If needed I will post the related code.
Hey, thanks for the suggestion. That was actually one of the first things I tried yesterday, and it had bad results/was not reliable/loaded very slow often.
That seems like a bit of a cheap trick though anyways, if you know what I mean.
I’d like to do it properly if there is a better way. It seems like it should be a very basic thing, yet I can’t find any information about it.
Any other suggestions would be great, thanks.
Edit: I got it working properly now with that method. Just had to fix other conflicting code I had which was causing issues.
I’d still like to know if there is a more proper way to do this though. =d
I’m honestly surprised if that’s the only way, it seems like such a basic thing that ahk should be able to do. =/
Oh by the way, it does work fine performance wise now, I just had some other related code causing issues.
I appreciate you trying to help by the way!
I’ll show the related code, but it won’t really help to find a better solution in this situation. =/
Hey Punchin.
Thanks, I’ll look into this and post back after. It sounds like it’s what I’m looking for. I’ll try mess around a bit.
Edit: Now that I think of it.. This actually sounds more technical then running the new instance, followed by exiting the old instance.
My question- So it’s not possible to change the running scripts directory after FileMove, without reloading?
There’s no way to change the variable A_ScriptDir or use SetWorkingDir to do the above^?
Looks like I didn’t explain myself well enough. It’s slightly more technical of an issue than what you’re thinking.
I’m starting to think it’s probably not possible to do what I want. I edited my last post, but basically this is the question/issue.
So it’s not possible to change the running scripts directory after FileMove, without reloading?
There’s no way to change the variable A_ScriptDir or use SetWorkingDir to do the above^?
If the above is not possible, I guess I’ll have to stick with the easiest way.
What I ask is to simplify the problem, because we don’t have to overview over the complete ahk script(s). So for me it is not clear why SetWorkingDir is not working on your installation.
What I ask is to simplify the problem, because we don’t have to overview over the complete ahk script(s). So for me it is not clear why SetWorkingDir is not working on your installation.
Ok, SetWorkingDir does seem to work, but not exactly, or at least not how I thought it would.
This is the problem.
-I Move the file (running ahk script) to a specific folder with FileMove.
-I use SetWorkingDir to change the running scripts directory.
-I Reload the script, which then causes the error «Script File Not Found».
(Moving the running script to a different location causes the issue, and I thought using SetWorkingDir would solved the problem.)
Basically it tries to reload A_ScriptDir but the file has been moved/directory has changed, so A_ScriptDir is now invalid, and reload fails.
So the problem is I cannot change the A_ScriptDir variable to the new directory, and get passed the script file error.
I hope that better explains what I mean.
When using Script-Parameters call it with
run %A_AhkPath% «EO+ OFFICIAL.ahk» «skip», %EODir%
And check with
Hope this is a solution for you.
FoxHunter: Thanks for trying to help, I already understood all that though, and that’s not what I’m looking to do.
If Reload will fail no matter what after moving the running script (changing directory) that’s all I need to know.
If that’s the case, I’ll just run the new script followed by exiting the old, like I mentioned before.
I don’t understand why Reload fails though, I’d think you should be able to change the script directory, followed by reloading.
I’m pretty confused as to how it’s not possible to change the scripts A_ScriptDir variable. I thought SetWorkingDir was for this purpose, no?
What is the difference between A_ScriptDir and SetWorkingDir? Why can’t A_ScriptDir be changed/updated?
I understand that A_Script is a variable containing the running scripts directory.. Why doesn’t SetWorkingDir or anything else effect this?
Seems like a limitation in ahk that should not exist if that’s the case. =/
Logically, it should be very possible to change a running scripts directory to bypass this error from a running file being moved, and allow a reload. =/
Anyways, to clarify, if there is no way to move a running file, and update it’s directory to bypass a file error, and allow a reload, then that’s all I need to know.
Obviously there is nothing more I can do in that situation. =/
Punchin: I assign the OutputVar to another variable immediately, because I will be using that variable throughout the script. I’ll also be using multiple outputvar checks, so putting the OutputVar into a new variable for global use is required for me.
Edit: Sorry in advance if I don’t respond until late. I have work and other things to do today, so I may not reply back until very late tonight or tomorrow.
Appreciate all the attempts at helping, thanks!
shift+c:: will not be active because it does not exist in the current layout
Then it says: Error invalid key or button name, specifically: shift+c, then shows some lines of code and says at botton «The program will exit»
Quick start tutorial
To create a new script:
Save and close the file.
In Windows Explorer, double-click the script to launch it. A new tray icon appears.
Hold down the Windows key and press the spacebar. A web page opens in the default browser.
To exit or edit the script, right click its tray icon.
im talking about eddting the script that autoloads when i start AutoHotKey.
Guys. None of you are answering his question:
Guys. None of you are answering his question:
yes I did. he has been running AutoHotkey from the Start Menu. so he doesn’t know where the default script is to edit it. my Solution link mentions Notepad. to REALLY drive it home.
To Edit the Default AutoHotkey Script.
Guys. None of you are answering his question:
yes I did. he has been running AutoHotkey from the Start Menu. so he doesn’t know where the default script is to edit it. my Solution link mentions Notepad. to REALLY drive it home.
[list] To Edit the Default AutoHotkey Script.
JS, can I lift the list of links you posted and put it in my help thread? It’s well collected.
yes but only if they remain purple linked. hehehe. I love the look of my purple links. (you can click quote to be able to copy the list already purple linked, just remove the excess
Windows explorer? i have an internet explorer.
Those instructions on the tutorial should just say My Computer (not Windows Explorer) or something else (like My Documents). & it should tell you how to get there, like I do.
To create a new AutoHotkey (.ahk) Script.
AHK utilman script gives file not found error
I’m trying to create a simple backdoor for myself through utilman on my computer using autohotkey. Basically I want to have the ease of access button function normally in all cases on login screen Except when I hold down the M key, where in this case it opens cmd instead. No batch or cmd window should pop up, and one doesn’t. The issue I’m having is that I get a file not found error from the script, I compiled the script into Utilman.exe and tested with a copy of the real utilman (renamed to lol.exe which is specified in the script to run normally) and this works fine in its own directory. However when I do this in the system32 folder it gives an error that lol.exe is not found, also executing lol.exe on it’s own gives the exact same error, as if it reroutes to the script named Utilman yet again. Here is the script, should be short and simple:
Thanks for any pointers, alternative suggestions or ideas. This would be great to get working.
EDIT: Changing Run lol.exe to Run, «C:\Windows\System32\lol.exe» now gives instead an exe corrupted error. This also happens if I run lol.exe on it’s own, I’m really not sure what’s happening.
EDIT2: Running the script from a different location again gives the file not found error, rather than the exe corrupted error.
This works perfectly everywhere EXCEPT the system32 folder, where it gives the exe corrupted error even when run with elevated permissions, this is frustrating.
1 Answer 1
1) Compile your script anywhere you want. I suggest using the following code as a basis:
2) In the registry, go to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
Your replacement will now run whenever an executable called utilman.exe is started.
4) Click the ease of access button. CMD will open when you hold down M before you click as well as when you press it just after the click. Modify the Sleep in the script above to rule how long to wait for the key press.
Update:
Both work while logged in, but none of them work while the screen is locked, triggering the server start error. Unfortunately, I’m at my wit’s end here. Maybe someone else has an idea.
Frequently Asked Questions (FAQ)
Table of Contents
Language Syntax
When are quotation marks used with commands and their parameters?
When exactly are variable names enclosed in percent signs?
Variable names are always enclosed in percent signs except in cases illustrated in bold below:
For further explanation of how percent signs are used, see Legacy Syntax and Dynamic Variables. Percent signs can also have other meanings:
When should percent signs and commas be escaped?
Literal percent signs must be escaped by preceding them with an accent/backtick. For example: MsgBox The current percentage is 25`%. Literal commas must also be escaped ( `, ) except when used in MsgBox or the last parameter of any command (in which case the accent is permitted but not necessary).
General Troubleshooting
What can I do if AutoHotkey won’t install?
7-zip Error: Use 7-zip or a compatible program to extract the setup files from the installer EXE, then run setup.exe or Installer.ahk (drag and drop Installer.ahk onto AutoHotkeyU32.exe).
AutoHotkey’s installer comes packaged as a 7-zip self-extracting archive which attempts to extract to the user’s Temp directory and execute a compiled script. Sometimes system policies or other factors prevent the files from being extracted or executed. Usually in such cases the message «7-zip Error» is displayed. Manually extracting the files to a different directory may help.
Setup hangs: If the setup window comes up blank or not at all, try one or both of the following:
Other: The suggestions above cover the most common problems. For further assistance, post on the forums.
Normally if AutoHotkey is installed, right-clicking an AutoHotkey script (.ahk) file should give the following options:
This can be done by applying this registry patch.
It may also be necessary to repair the default registry values, either by reinstalling AutoHotkey or by running AutoHotkey Setup (from the Start menu) and selecting apply near the top of the window.
Why do some lines in my script never execute?
Any lines you want to execute immediately when the script starts should appear at the top of the script, prior to the first hotkey, hotstring, or Return. For details, see auto-execute section.
Also, a hotkey that executes more than one line must list its first line beneath the hotkey, not on the same line. For example:
Why doesn’t my script work on Windows xxx even though it worked on a previous version?
There are many variations of this problem, such as:
If you’ve switched operating systems, it is likely that something else has also changed and may be affecting your script. For instance, if you’ve got a new computer, it might have different drivers or other software installed. If you’ve also updated to a newer version of AutoHotkey, find out which version you had before and then check the changelog and compatibility notes.
SoundGet, SoundSet, SoundGetWaveVolume and SoundSetWaveVolume behave differently on Vista and later than on earlier versions of Windows. In particular, device numbers are different and some components may be unavailable. Behaviour depends on the audio drivers, which are necessarily different to the ones used on XP. The soundcard analysis script can be used to find the correct device numbers.
Also refer to the following question:
How do I work around problems caused by User Account Control (UAC)?
User Account Control (UAC) is a common cause of problems, especially when moving from Windows XP/Vista/7 to Vista/7/8/10. Although it is present in Windows Vista and later, it is enabled by default on new systems or new installs, and it is more difficult to disable on Windows 8 and later.
By default, UAC protects «elevated» programs (that is, programs which are running as admin) from being automated by non-elevated programs, since that would allow them to bypass security restrictions. Hotkeys are also blocked, so for instance, a non-elevated program cannot spy on input intended for an elevated program.
UAC may also prevent SendPlay and BlockInput from working.
Common workarounds are as follows:
I can’t edit my script via tray icon because it won’t start due to an error. What do I do?
You need to fix the error in your script before you can get your tray icon back. But first, you need to find the script file.
Look for AutoHotkey.ahk in the following directories:
If you are running another AutoHotkey executable directly, the name of the script depends on the executable. For example, if you are running AutoHotkeyU32.exe, look for AutoHotkeyU32.ahk. Note that depending on your system settings the «.ahk» part may be hidden, but the file should have an icon like
You can usually edit a script file by right clicking it and selecting Edit Script. If that doesn’t work, you can open the file in Notepad or another editor.
If you launch AutoHotkey from the Start menu or by running AutoHotkey.exe directly (without command line parameters), it will look for a script in one of the locations shown above. Alternatively, you can create a script file (something.ahk) anywhere you like, and run the script file instead of running AutoHotkey.
How can I find and fix errors in my code?
For simple scripts, see Debugging a Script. To show contents of a variable, use MsgBox or ToolTip. For complex scripts, see Interactive Debugging.
Why is the Run command unable to launch my game or program?
Some programs need to be started in their own directories (when in doubt, it is usually best to do so). For example:
If the program you are trying to start is in %A_WinDir%\System32 and you are using AutoHotkey 32-bit on a 64-bit system, the File System Redirector may be interfering. To work around this, use %A_WinDir%\SysNative instead; this is a virtual directory only visible to 32-bit programs running on 64-bit systems.
Why are the non-ASCII characters in my script displaying or sending incorrectly?
Short answer: Save the script as UTF-8 with BOM.
Although AutoHotkey supports Unicode text, it is optimized for backward-compatibility, which means defaulting to the ANSI encoding rather than the more internationally recommended UTF-8. AutoHotkey will not automatically recognize a UTF-8 file unless it begins with a byte order mark.
In other words, UTF-8 files which lack a byte order mark are misinterpreted, causing non-ASCII characters to be decoded incorrectly. To resolve this, save the file as UTF-8 with BOM or add the /CP65001 command line switch.
To save as UTF-8 with BOM in Notepad, select UTF-8 from the Encoding drop-down in the Save As dialog.
Note that INI files accessed with the standard INI commands do not support UTF-8; they must be saved as ANSI or UTF-16.
Why do Hotstrings, Send, and Click have no effect in certain games?
Not all games allow AHK to send keys and clicks or receive pixel colors.
But there are some alternatives, try all the solutions mentioned below. If all these fail, it may not be possible for AHK to work with your game. Sometimes games have a hack and cheat prevention measure, such as GameGuard and Hackshield. If they do, there is a high chance that AutoHotkey will not work with that game.
Use SendPlay via the SendPlay command, SendMode Play and/or the hotstring option SP.
Note: SendPlay may have no effect at all on Windows Vista or later if User Account Control is enabled, even if the script is running as an administrator.
Increase SetKeyDelay. For example:
Try ControlSend, which might work in cases where the other Send modes fail:
Try the down and up event of a key with the various send methods:
Try the down and up event of a key with a Sleep between them:
How can performance be improved for games or at other times when the CPU is under heavy load?
If a script’s Hotkeys, Clicks, or Sends are noticeably slower than normal while the CPU is under heavy load, raising the script’s process-priority may help. To do this, include the following line near the top of the script:
My antivirus program flagged AutoHotkey or a compiled script as malware. Is it really a virus?
Although it is certainly possible that the file has been infected, most often these alerts are false positives, meaning that the antivirus program is mistaken. One common suggestion is to upload the file to an online service such as virustotal or Jotti and see what other antivirus programs have to say. If in doubt, you could send the file to the vendor of your antivirus software for confirmation. This might also help us and other AutoHotkey users, as the vendor may confirm it is a false positive and fix their product to play nice with AutoHotkey.
False positives might be more common for compiled scripts which have been compressed, such as with UPX (default for AutoHotkey 1.0 but not 1.1) or MPRESS (optional for AutoHotkey 1.1). As the default AutoHotkey installation does not include a compressor, compiled scripts are not compressed by default.
Common Tasks
Where can I find the official build, or older releases?
Can I run AHK from a USB drive?
How can the output of a command line operation be retrieved?
Testing shows that due to file caching, a temporary file can be very fast for relatively small outputs. In fact, if the file is deleted immediately after use, it often does not actually get written to disk. For example:
To avoid using a temporary file (especially if the output is large), consider using the Shell.Exec() method as shown in the examples for the Run command.
How can a script close, pause, suspend or reload other script(s)?
First, here is an example that closes another script:
To suspend, pause or reload another script, replace the last line above with one of these:
How can a repeating action be stopped without exiting the script?
To pause or resume the entire script at the press of a key, assign a hotkey to the Pause command as in this example:
To stop an action that is repeating inside a Loop, consider the following working example, which is a hotkey that both starts and stops its own repeating action. In other words, pressing the hotkey once will start the Loop. Pressing the same hotkey again will stop it.
How can context sensitive help for AutoHotkey commands be used in any editor?
How to detect when a web page is finished loading?
With Internet Explorer, perhaps the most reliable method is to use DllCall() and COM as demonstrated at www.autohotkey.com/forum/topic19256.html. On a related note, the contents of the address bar and status bar can be retrieved as demonstrated at www.autohotkey.com/forum/topic19255.html.
Older, less reliable method: The technique in the following example will work with MS Internet Explorer for most pages. A similar technique might work in other browsers:
How can dates and times be compared or manipulated?
To determine the amount of time between two dates or times, see EnvSub, which gives an example. Also, the built-in variable A_Now contains the current local time. Finally, there are several built-in date/time variables, as well as the FormatTime command to create a custom date/time string.
Scripts
Table of Contents
Introduction
Each script is a plain text file containing lines to be executed by the program (AutoHotkey.exe). A script may also contain hotkeys and hotstrings, or even consist entirely of them. However, in the absence of hotkeys and hotstrings, a script will perform its commands sequentially from top to bottom the moment it is launched.
The program loads the script into memory line by line, and each line may be up to 16,383 characters long. During loading, the script is optimized and validated. Any syntax errors will be displayed, and they must be corrected before the script can run.
The Top of the Script (the Auto-execute Section)
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
Note: While the script’s first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.
If the script is not persistent, it will terminate after the auto-execute section has completed. Otherwise, it will stay running in an idle state, responding to events such as hotkeys, hotstrings, GUI events, custom menu items, and timers. A script is automatically persistent if it contains hotkeys, hotstrings, OnMessage() or GUI, and in a few other cases. The #Persistent directive can also be used to explicitly make the script persistent.
If the auto-execute section takes a long time to complete (or never completes), the default values for the above settings will be put into effect after 100 milliseconds. When the auto-execute section finally completes (if ever), the defaults are updated again to be those that were in effect at the end of the auto-execute section. Thus, it’s usually best to make any desired changes to the defaults at the top of scripts that contain hotkeys, hotstrings, timers, or custom menu items. Also note that each thread retains its own collection of the above settings. Changes made to those settings will not affect other threads.
Splitting a Long Line into a Series of Shorter Ones
Long lines can be divided up into a collection of smaller ones to improve readability and maintainability. This does not reduce the script’s execution speed because such lines are merged in memory the moment the script launches.
Similarly, the following lines would get merged into a single line because the last two start with «and» or «or»:
The ternary operator is also a good candidate:
Although the indentation used in the examples above is optional, it might improve clarity by indicating which lines belong to ones above them. Also, it is not necessary to include extra spaces for lines starting with the words «AND» and «OR»; the program does this automatically. Finally, blank lines or comments may be added between or at the end of any of the lines in the above examples.
Method #2: This method should be used to merge a large number of lines or when the lines are not suitable for Method #1. Although this method is especially useful for auto-replace hotstrings, it can also be used with any command or expression. For example:
In the examples above, a series of lines is bounded at the top and bottom by a pair of parentheses. This is known as a continuation section. Notice that the bottom line contains FileAppend’s last parameter after the closing parenthesis. This practice is optional; it is done in cases like this so that the comma will be seen as a parameter-delimiter rather than a literal comma.
Known limitation: If the Join string ends with a colon, it must not be the last option on the line. For example, (Join: is treated as the label «(Join» and (LTrim Join: is unsupported, but (Join: C is okay.
RTrim0 (RTrim followed by a zero): Turns off the omission of spaces and tabs from the end of each line.
Comments (or Comment or Com or C) [v1.0.45.03+] : Allows semicolon comments inside the continuation section (but not /*..*/ ). Such comments (along with any spaces and tabs to their left) are entirely omitted from the joined result rather than being treated as literal text. Each comment can appear to the right of a line or on a new line by itself.
% (percent sign): Treats percent signs as literal rather than as variable references. This avoids the need to escape each percent sign to make it literal. This option is not needed in places where percent signs are already literal, such as auto-replace hotstrings.
, (comma): Treats commas as delimiters rather than as literal commas. This rarely-used option is necessary only for the commas between command parameters because in function calls, the type of comma does not matter. Also, this option transforms only those commas that actually delimit parameters. In other words, once the command’s final parameter is reached (or there are no parameters), subsequent commas are treated as literal commas regardless of this option.
` (accent): Treats each backtick character literally rather than as an escape character. This also prevents commas and percent signs from being explicitly and individually escaped. In addition, it prevents the translation of any explicitly specified escape sequences such as `r and `t.
) [v1.1.01+] : If a closing parenthesis appears in the continuation section’s options (except as a parameter of the Join option), the line is reinterpreted as an expression instead of the beginning of a continuation section. This allows expressions like (x.y)[z]() to work without the need to escape the opening parenthesis.
Escape sequences such as `n (linefeed) and `t (tab) are supported inside the continuation section except when the accent (`) option has been specified.
When the comment option is absent, semicolon and /*..*/ comments are not supported within the interior of a continuation section because they are seen as literal text. However, comments can be included on the bottom and top lines of the section. For example:
As a consequence of the above, semicolons never need to be escaped within a continuation section.
A continuation section cannot produce a line whose total length is greater than 16,383 characters (if it tries, the program will alert you the moment the script is launched). One way to work around this is to do a series of concatenations into a variable. For example:
A continuation section can be immediately followed by a line containing the open-parenthesis of another continuation section. This allows the options mentioned above to be varied during the course of building a single line.
The piecemeal construction of a continuation section by means of #Include is not supported.
Convert a Script to an EXE (Ahk2Exe)
A script compiler (courtesy of fincs, with additions by TAC109) is included with the program.
Once a script is compiled, it becomes a standalone executable; that is, AutoHotkey.exe is not required in order to run the script. The compilation process creates an executable file which contains the following: the AutoHotkey interpreter, the script, any files it includes, and any files it has incorporated via the FileInstall command. [v1.1.33+]: Additional files can be included using compiler directives.
Ahk2Exe can be used in the following ways:
Command Line: The compiler can be run from the command line by using the parameters shown below. If any command line parameters are used, the script is compiled immediately unless /gui is used. All parameters are optional, except that there must be one /gui or /in parameter.
The compiler’s source code and newer versions can be found at GitHub.
Base Executable File
Script Compiler Directives
[v1.1.33+]: Script compiler directives allow the user to specify details of how a script is to be compiled. Some of the features are:
Compressing Compiled Scripts
MPRESS official website (downloads and information): http://www.matcode.com/mpress.htm
MPRESS mirror: https://www.autohotkey.com/mpress/
UPX official website (downloads and information): https://upx.github.io/
Note: While compressing the script executable prevents casual inspection of the script’s source code using a plain text editor like Notepad or a PE resource editor, it does not prevent the source code from being extracted by tools dedicated to that purpose.
Background Information
The base file search algorithm runs for a short amount of time when Ahk2Exe starts, and works as follows:
A version of the AutoHotkey interpreter is also needed (as a utility) for a successful compile, and one is selected using a similar algorithm. In most cases the version of the interpreter used will match the version of the base file selected by the user for the compile.
Passing Command Line Parameters to a Script
Scripts support command line parameters. The format is:
And for compiled scripts, the format is:
Switches: Zero or more of the following:
Switch | Meaning | Works compiled? |
---|---|---|
/f or /force | Launch unconditionally, skipping any warning dialogs. This has the same effect as #SingleInstance Off. | Yes |
/r or /restart | Indicate that the script is being restarted (this is also used by the Reload command, internally). | Yes |
/ErrorStdOut /ErrorStdOut=Encoding | Yes | |
/Debug | [AHK_L 11+]: Connect to a debugging client. For more details, see Interactive Debugging. | No |
/CPn |