Click here to Skip to main content
14,173,149 members
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 16 Jun 2016
Licenced CPOL

C# ZKTeco Biometric Device Getting Started

, 12 May 2019
Rate this:
Please Sign up or sign in to vote.
An implementation of a Zkteco (K14) Biometric Device using C#


There are requirements where you have to integrate a biometric device into your own application or some part of it like fetching the attendance records, user information, backing up the fingerprint templates into your system database or export it somewhere remotely, etc.

For that very purpose, this article is written as a getting started guide with a few pieces of source code such that it helps C# developers to save some valuable time with all the troublesome work.

Note: Though the devices will be of various models, with a different set of sdk, the implementation procedure will be somewhat the same.

The following article contains some useful old pieces of code, if you ever get your hands on a biometric device (fingerprint reader for Time & Attendance) and want to extract gold(data) out of it.

Implemented Device Specification

Device Name : K14
Firmware Ver : ver. 4.0.1 ( build 39 )
Vendor : ZKTeco Inc.
FP : 500
Records : 50000
If you are working with a different model of the device like ZK4500, ZK9500, SLK20M or SLK20RHere is a good starting point for those device models.

Prior to going through the following article, it would be beneficial if you have some good understanding of the following things:

  • How a biometric device works, its features and functionalities
  • How to Register/ Unregister DLLs using the Regsvr32 utility
  • Knowledge about how the ref and out parameters work

The article and the source code provided will help you with the following things:

  • Registering the SDK components
  • Ping the device
  • Connecting to the device
  • Extracting some random data out of the device (Log Data, User Info, etc.)
  • Source code to upload data to the device
  • Restarting the device
  • How to register to device specific events [Not Implemented/ You will have to implement it yourself per your need]


Biometric Devices are being used extensively in many corporations through out the world these days. Companies like ZKTeco manufacture biometric access control and Time and Attendance in various shapes and sizes with different set of features per model. They provide a better way of user authentication and security in organizations who implement it. It is a growing demand in today's world. Hence, developers are likely to come across its implementation at some point.

Using the Code

Note: The follow procedures are applicable for the K14 model devices. Other devices might have a different set of SDK, hence a slightly different set of procedures.

In order to implement any biometric device, you will have to register the related components in the system, which can be easily done by using the Regsvr32 utility. If you don't know how it works, please go through some blog posts in the related topic. We already have a batch file ready for that very purpose, Hence, we are cool here.

You can download the SDK from here. I have already attached an SDK sample along with this article. You can go through the source code inside the Register_SDK.bat to see the registration mechanism.

Registering the Components

  1. Fire up a Command Prompt with Administrator Privilege
  2. Navigate to the SDK location
  3. Execute the Register_SDK batch file

On Successful Registration

To implement the biometric device, you will have to use the zkemkeeper.dll.

Implementing the SDK

  1. Add Reference to the zkemkeeper.dll in a project. The DLL gives access to the following things:

  2. Create a class file and implement the IZKEM interface.
  3. Use the CZKEM class file to perform device related operations.

Let's say your Biometric device is connected in the local area network. To make a successful communication with the device, you need to know the IP address and the Port No.

IP address : Assign a static IP in the device itself
Default Port : 4370
Machine No : 1

Now we have a valid IP and Port, let's go through the source code used in a demo project entitled BioMetrix which I have attached along with this article. The application helps by showing some of the API implementations.

The ZKenClient.cs file implements the IZKEM interface which contains the following code.

Connecting to the Device

The following code helps connect to the device at the given IPAddress and Port and on successful connection, it registers some events.

(The events are not implemented though, you will have to implement it yourself as per your need.)

public bool Connect_Net(string IPAdd, int Port)
    if (objCZKEM.Connect_Net(IPAdd, Port))
        if (objCZKEM.RegEvent(1, 65535))
            objCZKEM.OnConnected += ObjCZKEM_OnConnected;
            objCZKEM.OnDisConnected += objCZKEM_OnDisConnected; 
            objCZKEM.OnEnrollFinger += ObjCZKEM_OnEnrollFinger; 
            objCZKEM.OnFinger += ObjCZKEM_OnFinger; 
            objCZKEM.OnAttTransactionEx += 
               new _IZKEMEvents_OnAttTransactionExEventHandler(zkemClient_OnAttTransactionEx);
        return true;
    return false;

Registering Events

To fire any event when something occurs in the device, we need to register the event:

 bool RegEvent(int dwMachineNumber, int EventMask); 
// Entering 65535 for the EventMast value registers for all events

The EventMask requires an integer value whose value varies based on the type of event. The complete list of EventMast values are given below:

1   OnAttTransaction, OnAttTransactionEx
2 (1<<1) OnFinger
4 (1<<2) OnNewUser
8 (1<<3) OnEnrollFinger
16 (1<<4) OnKeyPress
256 (1<<7) OnVerify
512 (1<<8) OnFingerFeature
1024 (1<<9) OnDoor, OnAlarm
2048 (1<<10) OnHIDNum
4096 (1<<11) OnWriteCard
8192 (1<<12) OnEmptyCard
16384 (1<<13) OnDeleteTemplate

To register for multiple-events, we can perform XOR operations between binary codes of related events.

To register all real-time events, the value of Eventmast can be set as 65535 which I have implemented in the above code.

Fetching User Info

The user information can be fetched by providing the machine number. The API implements the out parameter to give back the output. I had stored some random user data in the fingerprint device and used the following code to retrieve it back and display it. The TmpData is the users (fingerprint) template data.

public ICollection<UserInfo> GetAllUserInfo(ZkemClient objZkeeper, int machineNumber)
    string sdwEnrollNumber = string.Empty, sName = string.Empty, 
                             sPassword = string.Empty, sTmpData = string.Empty;    
    int iPrivilege = 0, iTmpLength = 0, iFlag = 0, idwFingerIndex;
    bool bEnabled = false;

    ICollection<UserInfo> lstFPTemplates = new List<UserInfo>();
    while (objZkeeper.SSR_GetAllUserInfo(machineNumber, out sdwEnrollNumber, 
                      out sName, out sPassword, out iPrivilege, out bEnabled))
        for (idwFingerIndex = 0; idwFingerIndex < 10; idwFingerIndex++)
            if (objZkeeper.GetUserTmpExStr(machineNumber, sdwEnrollNumber, 
                   idwFingerIndex, out iFlag, out sTmpData, out iTmpLength))
                UserInfo fpInfo = new UserInfo();
                fpInfo.MachineNumber = machineNumber;
                fpInfo.EnrollNumber = sdwEnrollNumber;
                fpInfo.Name = sName;
                fpInfo.FingerIndex = idwFingerIndex;
                fpInfo.TmpData = sTmpData;
                fpInfo.Privelage = iPrivilege;
                fpInfo.Password = sPassword;
                fpInfo.Enabled = bEnabled;
                fpInfo.iFlag = iFlag.ToString();

    return lstFPTemplates;



Well, that gives you the starting point for your project. With a biometric device in hand, you can now experiment with the source code yourself and play along.

There are numerous procedures and events to be implemented which you can use per you need. Also, you might want to take help from the SDK that I have attached along with this article. There are other SDK/manuals which you can find online for more detailed implementation.

Feel free for any queries and feedbacks.

Peace !!


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


About the Author

Ozesh Thapa
Software Developer Braindigit IT Solution
Nepal Nepal
I am a Software Engineer and a developer by profession.

The following things describes me:
1. I am a real time/run time developer : Basically learn and implement things on the fly.
2. Definitely not a technology racist : Love to work and explore any technology that i come across.
3. Prefer Beer over H2O : Code with passion and for fun

I am interested in Research & Development based tasks, exploring, experimenting and trying out new things.
Technologies i have been using up until now are C#, ASP.NET, Win Services, Web Services, Restful Web API, Windows Application, Windows Phone Application, Store Apps, couple of JavaScript frameworks, Xamarin Forms, NodeJS, React, ReactNative, AngularJS, SQL Server, MongoDB, Postgres etc.

You may also be interested in...


Comments and Discussions

QuestionBackup and Restore Fingerprint Pin
gonzaloleon9hrs 32mins ago
membergonzaloleon9hrs 32mins ago 
BugError code -201 Pin
Osempu19hrs 48mins ago
memberOsempu19hrs 48mins ago 
AnswerRe: Error code -201 Pin
OriginalGriff19hrs 46mins ago
protectorOriginalGriff19hrs 46mins ago 
Questionzkteco k40 sdk Pin
Member 122810810-May-19 13:41
memberMember 122810810-May-19 13:41 
QuestionSetUserTmpStr not working Pin
Member 1436243210-May-19 4:00
memberMember 1436243210-May-19 4:00 
Questionhow to get log data between date range? Pin
Member 143482824-May-19 23:36
memberMember 143482824-May-19 23:36 
QuestionUnable to get User Info / Data Log with F7 Model Pin
Marcus Tan4-May-19 8:36
memberMarcus Tan4-May-19 8:36 
QuestionI can't get Card Number in Code Sample Pin
phucbac3-May-19 0:19
memberphucbac3-May-19 0:19 
AnswerRe: I can't get Card Number in Code Sample Pin
Member 1436243210-May-19 1:58
memberMember 1436243210-May-19 1:58 
Questionzkt multiple device Pin
Member 1410956528-Apr-19 2:37
memberMember 1410956528-Apr-19 2:37 
QuestionI have a device ZkTeco K40, Pin
Member 1054887018-Mar-19 20:59
memberMember 1054887018-Mar-19 20:59 
GeneralRe: I have a device ZkTeco K40, Pin
Hafsa Khan14-Apr-19 21:47
memberHafsa Khan14-Apr-19 21:47 
QuestionFinger print request to device Pin
Member 1165637521-Feb-19 6:49
memberMember 1165637521-Feb-19 6:49 
Questioncapture the fingerprint Pin
Member 1405901211-Feb-19 18:57
memberMember 1405901211-Feb-19 18:57 
QuestionIs there any SDK available in Php like what you did using C#? Pin
Jem Bros5-Feb-19 16:23
memberJem Bros5-Feb-19 16:23 
AnswerRe: Is there any SDK available in Php like what you did using C#? Pin
Member 1415501618-Feb-19 22:06
memberMember 1415501618-Feb-19 22:06 
QuestionNot working with InBio160/260/460 Controller please share code for InBio Controller Pin
Member 140542131-Feb-19 0:29
memberMember 140542131-Feb-19 0:29 
QuestionUser active & inactive Pin
Mahmudunnabi18-Dec-18 0:19
memberMahmudunnabi18-Dec-18 0:19 
QuestionBiometrics devece using Model F17 Pin
Member 1283711911-Dec-18 1:01
memberMember 1283711911-Dec-18 1:01 
QuestionAbout register new user with face Pin
Mohamed Salah Tag6-Nov-18 4:58
memberMohamed Salah Tag6-Nov-18 4:58 
Questionhow can i get in/out status Pin
Member 140043871-Oct-18 22:54
memberMember 140043871-Oct-18 22:54 
QuestionHow to get the image fingerprint from TmpData ? Pin
Mohammed Alromimah27-Sep-18 12:32
professionalMohammed Alromimah27-Sep-18 12:32 
AnswerRe: How to get the image fingerprint from TmpData ? Pin
Member 1408804231-Dec-18 0:31
memberMember 1408804231-Dec-18 0:31 
QuestionConnection does not work on differente threads Pin
Member 1393313921-Sep-18 15:50
memberMember 1393313921-Sep-18 15:50 
GeneralMy vote of 5 Pin
Maciej Los20-Sep-18 21:10
protectorMaciej Los20-Sep-18 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190524.3 | Last Updated 13 May 2019
Article Copyright 2016 by Ozesh Thapa
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid