Run windows defender scan

broken image

Var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(obj)) Private static IntPtr StructToPtr(object obj) Result = MpScanStart(phMpHandle, 3, 0, resourcePointer, IntPtr.Zero, out phScanHandle) **//Getting Access violation exception here**.Īnd the structure is defined here. IntPtr resourcePointer = StructToPtr(scanResource) ScanResource.pResourceList = pResourceList TagMPSCAN_RESOURCES scanResource = new tagMPSCAN_RESOURCES() PResourceList.SetValue(mpResourceInfo, 0)

broken image

TagMPRESOURCE_INFO pResourceList = new tagMPRESOURCE_INFO TagMPRESOURCE_INFO mpResourceInfo = new tagMPRESOURCE_INFO() MpManagerOpen(dwReserved, out phMpHandle) //Opens Defender and returns the handle in phMpHandle. Int result = WDStatus(out pfEnabled) //Returns the defender status - It's working properly.ĮrrorHandler.ThrowOnFailure(result, VSConstants.S_OK) Private void DoDefenderScan_Click(object sender, EventArgs e) Public static extern int MpHandleClose(IntPtr hMpHandle)

broken image

Public static extern int MpScanStart(IntPtr hMpHandle, uint ScanType, uint dwScanOptions, IntPtr pScanResources, IntPtr pCallbackInfo, out IntPtr Files\Windows Defender\MpClient.dll')] Public static extern int MpManagerOpen(uint dwReserved, out IntPtr Files\Windows Defender\MpClient.dll')] Public static extern int WDStatus(out bool Files\Windows Defender\MpClient.dll')] We are writing a code to do on-demand scan of a file from C# using Windows Defender APIs.