An electronic system for locking doors or windows, comprising: - a counter-plate installable on a fixed frame of the door or window; - an electronic lock installable on a wing of the door or window and provided with closing means (7, 8) mobile between a release configuration, in which the closing means (7, 8) engages the counter-plate when the counter-plate is proximal to the electronic lock, and a retained configuration, in which the closing means (7, 8) is maintained inside the electronic lock and does not engage the counter-plate, wherein said electronic lock comprises an opening device configured to activate a switching of the closing means (7, 8) at least between the retained configuration and the release configuration, characterised in that it comprises a control system for controlling the opening of the door or window comprising: - a first infrared device arranged in the counter-plate and configured to transmit at least a first optical signal or activating optical signal containing an activating message and to receive at least a second optical signal, - a second infrared device arranged in the electronic lock and configured to receive said first optical signal and to transmit said second optical signal, said second optical signal comprising a message relating to the status of the wing and/or an authentication message suitable for being used by the first infrared device for authenticating the activating message previously sent via the first optical signal, said first and second infrared device (12, 13) being positioned in a condition of reciprocal visibility at least when the counter-plate is proximal to the electronic lock. - a counter-plate installable on a fixed frame of the door or window; - an electronic lock installable on a wing of the door or window and provided with closing means (7, 8) mobile between a release configuration, in which the closing means (7, 8) engages the counter-plate when the counter-plate is proximal to the electronic lock, and a retained configuration, in which the closing means (7, 8) is maintained inside the electronic lock and does not engage the counter-plate, wherein said electronic lock comprises an opening device configured to activate a switching of the closing means (7, 8) at least between the retained configuration and the release configuration, characterised in that it comprises a control system for controlling the opening of the door or window comprising: - a first infrared device arranged in the counter-plate and configured to transmit at least a first optical signal or activating optical signal containing an activating message and to receive at least a second optical signal, - a second infrared device arranged in the electronic lock and configured to receive said first optical signal and to transmit said second optical signal, said second optical signal comprising a message relating to the status of the wing and/or an authentication message suitable for being used by the first infrared device for authenticating the activating message previously sent via the first optical signal, - a first infrared device arranged in the counter-plate and configured to transmit at least a first optical signal or activating optical signal containing an activating message and to receive at least a second optical signal, - a second infrared device arranged in the electronic lock and configured to receive said first optical signal and to transmit said second optical signal, said second optical signal comprising a message relating to the status of the wing and/or an authentication message suitable for being used by the first infrared device for authenticating the activating message previously sent via the first optical signal,