Windows Biometric Framework: AcquireFocus() not wokring. Error AccessDenied : 0x80070005


I am developing a windows service to capture fingerprint sample. WBF (Windows Bio metric Framework) requires focus to capture sample image, for which i am using AcquireFocus().

Exporting from DLL is as follows.

 class Focus
        protected const string LibName = "winbio.dll";

        [DllImport(LibName, EntryPoint = "WinBioAcquireFocus")]
        public static extern WinBioErrorCode WinBioAcquireFocus();

        [DllImport(LibName, EntryPoint = "WinBioReleaseFocus")]
        public static extern WinBioErrorCode WinBioReleaseFocus();

Usage is as follows

WriteToFile(DateTime.Now + " Acquiring Focus" + "\n");
re = Focus.WinBioAcquireFocus();
if (re.Equals(WinBioErrorCode.Ok)){
    WriteToFile(DateTime.Now + " Calling CaptureSample Image." + "\n");
    result = wbf.CaptureSampleImage();
     WriteToFile(DateTime.Now + " Error in Acquiring Focus: " + re + "\n");

This function requires the process to be running on LocalSystem account as mentioned in documnetation. I have set this in service settings.

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

CaptureSampleImage() is defined in a DLL. Now i am always getting error 0x80070005 which is Access denied. Log file is as follows.

10/22/2019 4:16:06 PM Acquiring Focus

10/22/2019 4:16:06 PM Error in Acquiring Focus: AccessDenied

10/22/2019 4:16:06 PM Stopping Service.

Error codes are defined as Enum as follows

    public enum WinBioErrorCode
         : uint
        Ok = 0,
        False = 1,
        AccessDenied = 0x80070005,

The documnetation says that this arises due to service not being on LocalSystem, whereas it is.

For logging purposes, i have written writeToFile(message), that write message to .txt file.

What can i do to remove this error?

Thanks in advance.

asked on Stack Overflow Oct 22, 2019 by Awais Waheed • edited Oct 22, 2019 by Awais Waheed

1 Answer


Add AcquireFocus() right after WinBioOpenSession(). Then it will acquire focus for that session and return S_OK.

answered on Stack Overflow Oct 23, 2019 by Awais Waheed

User contributions licensed under CC BY-SA 3.0