Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hello guys,
I would like to disable Windows Defender ("WinDefend") service using C # code.
I have tried something like the code below, but this does not work with Windows 10.
This code below works with Windows 7, but not work at Windows 10.
Please for help. Thank you.

What I have tried:

private void disabledefender()
        {           
                    RunCmd("/c net stop WinDefend");
                    ProcStartargs("powershell", "-command \"Set-Service -Name WinDefend -StartupType Disabled\"");
                    _OutPut("Windows Defender disabled");       
               Registry.SetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\WinDefend", "Start", 4);          
        }
Posted
Updated 13-Feb-17 4:26am
v2
Comments
[no name] 12-Feb-17 13:05pm    
Why would you want to do something malicious?
Afzaal Ahmad Zeeshan 12-Feb-17 14:48pm    
Is yours off? If so, look for any hacking website and ask them to remotely connect and write the code for you. :-)

1 solution

The very same code will work so long as your executable is run with admin permissions.

Though, like everyone has already said, why would you want to do such a risky thing?

Oh, and setting the service to Disable may also require you to Stop the service first.
 
Share this answer
 
Comments
Dave Kreskowiak 1-Feb-20 9:42am    
"Virus is detected". What does that say about the machine your developing this on?
@cromx 1-Feb-20 20:52pm    
What do you mean what does it say? I'm working on a simple app that auto-checks and cleans USB drives if there is a virus detected by it. However, Windows Defender stops the process and causes an exception (as stated above).
Dave Kreskowiak 1-Feb-20 22:45pm    
Well, either you have a virus on your dev machine that's building the executable and infecting it, or Defender is seeing what your code is doing and suspecting it's a virus.

Besides, NOBODY is going to want Defender deactivated so your app can do a terrible job of identifying viruses.
@cromx 1-Feb-20 23:18pm    
No you do not understand . My dev machine doesn't have the virus, it is the USB drive that has (since I am experimenting/debugging). It is not my app that the Defender sees as virus. When my app auto-scans the inserted USB drive, the Windows Defender DOES NOT ALLOW it because the file it scans is A VIRUS (the code is that it reads the 2 bytes of the file).

So what I did is that I made the code to TEMPORARILY disable REAL-TIME protection for the scanning to continue then RE-ENABLE it again AFTER the scanning. Do you get it? (my bad I didn't make it clearer and English isn't my native lang)
Dave Kreskowiak 2-Feb-20 23:51pm    
Yes, I do get it.

No, you can't disable it from your code. Think about it. If it was that easy, any old virus would do it itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900