TheName
TheName

Reputation: 733

Go lang access denied

I'm new to the GO programming language, what I'm trying to do is to put some items into the map and then remove one of them, when I'm trying to remove one of the items from array I'm getting the error message:

C:/Go\bin\go.exe run C:/Users/Computer/IdeaProjects/untitled1/simple.go
fork/exec C:\Users\Computer\AppData\Local\Temp\go-build143466426\command-line-arguments\_obj\exe\simple.exe: Access is denied.

the code:

package main

import "fmt"

    func main(){
    
        presAge := make(map[string] int)
    
        presAge["test"] = 42
        presAge["boom"] = 421
    
        delete(presAge,"boom")
    
        fmt.Println(len(presAge))
    
    }

Upvotes: 14

Views: 30705

Answers (10)

bjhoohaha
bjhoohaha

Reputation: 76

For me,

It was Windows Defender that was blocking the .exe.

I had trouble with the suggestion provided by @mnhmilu by adding Exclusions under Windows Settings because I was using a company device and the settings were managed by my IT department. However, IT has no clue as to what was actually causing the issue.

I fixed the issue by having to programmetically add exclusion paths to ...\AppData\Local\Temp using powershell running as administrator.

powershell -Command Add-MpPreference -ExclusionPath "C:\Users\Computer\AppData\Local\Temp"

Upvotes: 0

mnhmilu
mnhmilu

Reputation: 2468

Adding code folder to the exception list solved the problem

Windows Security-> Virus and Threat Protection Settings -> Exclutions->Add folder

Add your workplace folder here where your code exists. Adding temp folder didn't work for me.

go build gotest.go ; .\gotest.exe

Using the above command (regular command prompt.) can eliminate pop-up alerts but don't know the reason.

Upvotes: 1

Alex Galo
Alex Galo

Reputation: 1

This happened to me too, but it's not a Go problem, it's a Windows problem. I didn't have any antivirus going on, so what I did was that if I was going to work with Go, (whatever the text editor) I run it as admin. That solved my problem (WINDOWS only)

Upvotes: -1

This worked for me as I had no admin rights to deactivate my antivirus

go build main.exe; main./exe

Upvotes: 0

manu_singh
manu_singh

Reputation: 63

**** Only Applies if you have avira antivirus installed on your pc ****

The thing is that avira recognises the go interpreter similar to a certain virus(HEUR/APC). So it blocks it and we get this error.

see the first row

Just go to settings in the same page and add a exception to a folder like i have done so.

add this path to the exception : C:\Users\User\AppData\Local

Then press Ok and apply and you'll be good to go.

P.S. - I see that someone else also pointed out that it's the avira antivirus but didn't give proper solution to the problem, so i thought to give a proper solution from my side.

Upvotes: 3

adals
adals

Reputation: 79

for me I used avira just add C:\Users\Computer\AppData\Local\Temp floder to exception folder for realtime-protection.

Solved my problem

Upvotes: 7

TheName
TheName

Reputation: 733

so the trick here is that you need to run your application as Administrator in Windows

Upvotes: 1

Surabhi Priya
Surabhi Priya

Reputation: 1

I am getting the same error and its because of my Cylance Protect antivirus. Try disabling it.

Upvotes: -1

Nicholas
Nicholas

Reputation: 2668

I can only speak for my own case. I ran into the similar error using Windows 10. After some experiments, it looks like the error came from Avira, the anti-virus software I was using. Basically, the .exe file is detected by Avira as containing the pattern of a type of virus (called HEUR/APC (Cloud) in my case), which prevents the program from executing.

After I disabled my anti-virus software, everything went back to normal.

Upvotes: 15

Gabriele Carioli
Gabriele Carioli

Reputation: 449

Your code is correct. You can run it via https://play.golang.org/ and it will print "1"

The error you're getting is not a Go error but a Windows error. It looks like a permission problem (no idea why you're getting it)

Upvotes: 1

Related Questions