- Fix: The Process Cannot Access the File Because It is Being Used by Another Process
- What causes the process to be used by another process?
- Method 1: Running the command with admin privileges
- Method 2: Setting a different IP range
- Method 3: Resolving the IIS port conflict
- Windows 10 hosts file used by another process
- 4 Answers 4
- Reading a file used by another process [duplicate]
- 2 Answers 2
Fix: The Process Cannot Access the File Because It is Being Used by Another Process
Several Windows users are encountering the “The process cannot access the file because it is being used by another process” error. Most of the time, the issue occurs when the user tries to run a netsh command. Some users are reporting that for them, the error message appears when they try to right-click a website in the IIS (Internet Information Services ) MMC (Microsoft Management Console) snap-in.
The process cannot access the file because it is being used by another process
The issue is reported to occur on Windows Vista, Windows 7, Windows 8.1, Windows 10 and on various Windows Server versions.
What causes the process to be used by another process?
We investigated this particular issue by looking at various user reports and the repair strategies that they used to get the issue resolved. Based on what we were able to gather, there are several common scenarios that will trigger this particular error message:
- The command requires admin privileges – If you’re encountering the error inside a terminal, it’s most likely because you don’t have administrative privileges to make the modifications. Several users in a similar situation have managed to get the issue resolved by granting admin privileges.
- Another process is using port 80 or port 443 – This is typical with computers running IIS (Internet Information Services). If another process is using these two ports, you will see this error message.
- The ListenOnlyList registry subkey is not configured correctly – Another common scenario with IIS (Internet Information services) that will trigger this particular error is an incorrectly configured ListenOnlyList registry subkey.
If you’re currently struggling to resolve this particular error message, this article will provide you with a collection of verified troubleshooting steps. Down below, you have a collection of methods that other users in a similar situation have used to get the issue resolved.
For the best results, follow the methods below in order until you encounter a fix that is effective in resolving the error in your particular scenario.
Method 1: Running the command with admin privileges
If you’re getting this error when trying to run a netsh command, it’s likely that the error is occurring because you don’t have admin privileges. This is reported to occur more than often when the user tries to run a command that adds exclusions to the dynamic port range for native Windows apps or 3rd party application.
Keep in mind that an operation of this kind will require administrator privileges. To ensure that the CMD window you’re trying to perform the action in has admin privileges, follow the steps below:
- Press Windows key + R to open up a Run dialog box. Then, type “cmd” and press Ctrl + Shift + Enter to open up an elevated Command Prompt.
Opening an elevated Command Prompt window
- When prompted by the UAC (User Account Control), click Yes to grant admin privileges.
If you’re still getting the “The process cannot access the file because it is being used by another process” error or this scenario wasn’t applicable, move down to the next method below.
Method 2: Setting a different IP range
If you’re trying to resolve a conflict DNS conflict using netsh and the method above didn’t help you, you might want to try a different approach.
Several users struggling to resolve the same error message have found that the conflict is resolved after they tried to set a completely different IP range instead of creating an exclusion range.
Below you have a couple of commands that one affected user successfully ran to resolve a conflict between DNS and Quickbooks:
Note: Ensure that the terminal you’re running the command in has admin privileges.
If this method didn’t resolve the conflict or wasn’t applicable to the situation that you’re encountering, move down to the final method.
Method 3: Resolving the IIS port conflict
If you are encountering the issue while trying to right-click a website item inside the IIS MMC snap-in (clicking Start doesn’t do anything), you’ll need to use the Netstat.exe utility to figure out if another process is using port 80 and port 443.
This issue is quite common with computers running Microsoft IIS 6.0 and 7.0. Based on the official Microsoft documentation, the error message will appear if one of the following conditions are applicable to your current situation:
- The ListenOnlyList registry subkey is not configured correctly on the IIS running computer.
- Another process is using the TCP port (80) or the SSL port (443) required by the IIS.
To resolve this issue, we’ll need to deploy the Netstat.exe utility in order to determine if another process is using the ports specified above. If the utility determines that the ports are not being used, we’ll examine the ListenOnlyList subkey to see if it’s correctly configured.
Here’s a step-by-step guide through the whole thing:
- Press Windows key + R to open up a Run dialog box. Then, type “cmd” and press Ctrl + Shift + Enter to open up an elevated Command Prompt. When prompted by the UAC (User Account Control), click Yes to grant administrative privileges.
Opening an elevated Command Prompt window
- Inside the elevated command prompt, run the following command to start the Netstat.exe utility:
- Once you get a return, scroll through the list of Active Connections and verify whether the ports 50 and 443 are being actively used by a different process.
Verifying if the ports are being used by a different process
Note: If the ports are being actively used by a different process, you’ve just managed to identify the source of your problem. In this case, look online for specific steps on how to resolve the port conflict according to the PID of the port.
Note: In case the ListenOnlyList subkey is not present, there’s no need to create one as an IP address of 0.0.0.0 will be used by default.
Note: In case the ListenOnlyList subkey is present and the 0.0.0.0 address is listed, you need to delete all the other IP addresses.
Note: If you get returned a message saying that “The requested service has been already started” you are good to go.
Windows 10 hosts file used by another process
There are a few other question with this same title but they do not solve my problem, so I am opening another one.
I have set the permission for the «hosts» file to full access for the current user. I have even taken the ownership. Current user is in Administrators group.
I have turned off UAC.
I have removed read only permission from the file.
I have disabled my Panada Antivirus. I have also stopped 3 panda services from Services palette.
I open an elevated Command Line (run as Administrator). Run Notepad and change the file. When I try to save the file I receive the following error:
«The process cannot access the file because it is being used by another process.
I check the file using «Unlocker» and the software says there is no active lock on the file.
Can anyone help?
4 Answers 4
My etc\hosts file was locked by ZoneAlarm Firewall
To unlock, I had to uncheck the «Lock hosts file» in ZoneAlarm firewall settings menu
Just came across and solved this issue, after a little faffing, so thought I’d offer notes.
I used SysInternals Process Explorer, Run as Administrator, to find the process that was locking the file (by using Find > Find Handle or DLL ). Note that when I ran it without Administrator permissions it couldn’t see the system-level WRSA process.
In my case it was WRSA.exe , which is Webroot Secure Anywhere. Disabling the protection unlocked the file and I was able to overwrite it easily. In some versions of webroot you will have to open «Advanced Settings > Shields» and un-check the option for blocking edits to the hosts file.
It’s completely right that anti-virus software should protect files such as hosts , of course. Malware loves that sort of thing.
I could eventually find the culprit. It was a program called «Tiny Firewall» (a windows firewall rule management software) that caused the problem.
I am not exactly sure what does it do to the hosts file because none of the available software could show a lock on the file. I could find that it is somehow involved with the file using process monitor (Sysinternals). I quit the UI and stopped the process (would not allow to stop, killed the process-tree and set to manual service).
P.S.: This is a feature of Tiny Firewall (protection of hosts file) and you can simply turn it off from its settings.
In my case, HOSTS file was constantly locked by svchost.exe !
The problem started since I have used the tool HostsMan. It had filled the HOSTS file with about 18 MBs of DNS numbers and domains. And my PC was suddenly offline.
So, with the tool Process Explorer, I searched for «etc\HOSTS». When you click on one entry in the search results, the corresponding locking process is highlighted in brown colour. So I found out, that HOSTS file had been locked by the process svchost.exe and sometimes by other processes as well. I waited until no other process than svchost.exe had been locking HOSTS. Then I killed the process tree of that concerning svhosts.exe! Within the few seconds, while that svhosts.exe process had not yet restarted (thus HOSTS was temporaily unlocked), I finally managed to rename HOSTS manually into anything else like «HOSTS000». Then I renamed the neighbouring file «HOSTS.back» (which is the backup with the default content) into HOSTS. Problem solved! I suddenly was online again.
Check the picture below for the DNS filters, which I had activated. I guess, Windows 10 simply was overloaded with all those 50 thousands of domain names saved into the HOSTS file.
Reading a file used by another process [duplicate]
I am monitoring a text file that is being written to by a server program. Every time the file is changed the content will be outputted to a window in my program.
The problem is that I can’t use the Streamreader on the file as it is being used by another process . Setting up a Filestream with ReadWrite won’t do any good since I cannot control the process that is using the file.
I can open the file in notepad. It must be possible to access it even though the server is using it.
Is there a good way around this?
Should I do the following?
- Monitor the file
- Make a temp copy of it when it changes
- Read the temp copy
- Delete the temp copy.
I need to get the text in the file whenever the server changes it.
2 Answers 2
If notepad can read the file then so can you, clearly the program didn’t put a read lock on the file. The problem you’re running into is that StreamReader will open the file with FileShare.Read. Which denies write access. That can’t work, the other program already gained write access.
You’ll need to create the StreamReader like this:
Guessing at the Encoding here. You have to be careful with this kind of code, the other program is actively writing to the file. You won’t get a very reliable end-of-file indication, getting a partial last line is quite possible. In particular troublesome when you keep reading the file to try to get whatever the program appended.