Can't save batch file shortly after running it on Windows 7
I'm working on a batch file in Windows 7 Ultimate. I'm using notepad++ with the runme extension.
When I run the batch file and make some changes directly after that, I am not able to save the .bat file, because windows says it's been used by another process.
So I need to wait about 60 seconds until I'm able to re-save the file to test the changes.
Same goes when using the built-in Notepad.
Strangely I can delete the .bat file directly after running it, but saving doesn't work.
Some months ago, when I was working on another batch-file, everything was working ok.
Is there any way to stop this strange behaviour? Or is there at least any way to see which process is blocking the file?
Solution
The problem happens when the Application Experience service (AeLookupSvc
) is disabled:
If the Application Experience service has been disabled, [Windows] Explorer may hold on to an executable file handle lock for an extended time.
Source: Linker Tools Error LNK1168
- Open an elevated command prompt.
-
Type or paste the following command:
sc config "AeLookupSvc" start= demand
Restart Windows.
Additional information
The Application Experience service (
AELookupSvc
) is a part of the Application Compatibility Administrator. It processes application compatibility lookup requests for applications as they are started, provides support for computers running programs in compatibility mode, reports on compatibility issues, and automatically applies software updates to programs.The Application Experience service must be active for application compatibility software updates to be applied. You cannot customize this service; the operating system uses it internally. [...]
If you disable the Application Experience service, the service continues to run, but no calls are made to the service. You cannot stop the actual process.
The Application Experience service is configured for a Manual start.
Source: Threats and Countermeasures Guide: System Services
Application Compatibility attempts to check if the .EXE file requires any application compatibility shims when it is accessed. This causes the system to obtain a handle to the file. The system queues a lookup request to the Application Experience (
AeLookupSvc
) service, but since the service is disabled, the request is not serviced in time and the file [cannot be accessed] because it is in use. After two minutes, the queued request to the Application Experience service times out and is dropped, releasing the handle.Source: Copying .EXE files may result in a sharing violation error - Folder In Use