-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo run
fails with Access is denied. (os error 5)
on Windows 10
#11544
Comments
For reference, the output of Show...
|
Hm, that's quite strange! Some questions:
|
Our anti-virus is Windows Defender Antivirus. Versions here:
PowerShell version:
Execution policy:
Yes, I think there are non-default system policies, but I don't know them in detail I'm afraid. From your questions it sounds like this might just be my environment not allowing me access - I will talk to the policy issuers and see if they can give any more insight. |
Hm. RemoteSigned is not the default, but I tested on my local machine and it didn't seem to make a difference. Another random thought is to check if there are any AppLocker policies. I think those can be listed with Another place to check is the Event Viewer and scrounge around to see if there are any events logged when the Access is Denied error is raised. Otherwise, I'm not familiar with Windows policies or anti-virus controls, so I probably won't be able to help much more. Perhaps there are some Windows experts at one of the forums like https://users.rust-lang.org/? |
AppLocker policies:
I will investigate the Event Viewer and update this thread if I find anything interesting. It seems right now that my problem is being caused by a policy on my machine causing the issue, not necessarily a problem with |
Hey. Thank you for helping the investigation. I am going to close this issue to make the way too long issue backlog less scary. If you find anything interesting or any improvement Cargo can do for this situation, feel free to comment below or open a new issue. Thank you again! |
I have the same error. I am new to this programming language. I am using Windows 11. |
I found a workaround for this after some more searching: https://stackoverflow.com/a/74170163 Adding the Rust workspace folder to Microsoft Defender's exclusion list prevents the problem from happening. I'm not sure there is anything Cargo can do in this situation, it's more related to OS security policies than the program itself, so I am happy if this thread stays closed. Thanks for everyone's help. |
In my case it was avast hardened mode. |
In my case, the program was already running in Visual Studio Code's terminal and I was trying cargo run in powershell |
in my case, it was by ESET antivirus. disabled it to solved |
On Windows 10 I had to click Virus & threat protection > Virus & threat protection: Manage settings > Exclusions: Add or remove exclusions > + Add an exclusion |
Windows Security was the culprit for me as well. I hooked up ProcMon to see what exactly gave the error, and it was a call to
Note that I was running |
Hm, my guess is that happens because the directory Edit: actually a better guess is the security software has a lock on something in the source directory. This would also prevent renaming the ancestor directories. A quick fix would be to keep retrying the operation with a back-off until either it succeeds or some arbitrary limit is reached (whichever comes first). |
Seems it comes with last MS or similar updates. New projects won't work like described above. Older ones are working for me. Cargo run then does it without OS error 5. |
I did a cargo clean and the deleted cargo.lock it seems fine now |
It seemed it would work for me, but alas it failed with same OS error. After some trials, it does not always stop at the same point thought. Last week, my company installed an upgrade of the antivirus on my development computer, and it really seems to be the root cause. |
If you're able to use dev drive on your developer computer then that might improve the situation. |
Problem
Following the instructions on https://www.rust-lang.org/tools/install I used
rustup-init.exe
to install Rust on my Windows 10 machine.I created a new Rust project by running
cargo new playground
in PowerShell, changed to the new directory withcd \.playground\
, and rancargo run
. The error I get is as follows:However, if I run the binary directly in PowerShell (after
cargo build
or attemptingcargo run
), it works:I looked up several similar issues to this, but these didn't lead to any solutions:
cargo new <packagename>
on Windows 10 will notcargo run
: "error: Access is denied. (os error 5)" #10671Things I have tried so far which don't fix the problem:
rustup-init.exe
installerrustc
, copying the binary intotarget\debug\playground.exe
and then runningcargo run
cargo run
withRUST_BACKTRACE=1
andCARGO_LOG=trace
environment variables to try and diagnose the issue - no extra useful outputtarget
directory - permissions look fine to meAccess is denied.
error, whereas this approach works in PowerShellrustup-init.exe
installer as administrator (without uninstalling as a regular user first)One thing I have not tried yet is disabling my antivirus, because this is managed by my company. However, I have seen people with a similar issue to myself (see links above) and they mention that disabling antivirus did not fix the issue for them.
Steps
cargo new playground
cargo run
(should produce the error).\target\debug\playground.exe
(should work successfully)cargo run
(should produce the error)Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: