A system for controlling pests in buildings comprises an electric fence band (100) to be fastened to a building, which electric fence band (100) is fastened essentially in a horizontal line onto the stone wall or foundation of the building essentially above the ground level of the building and below the wooden structure (102) of the building by means of fasteners (103) manufactured from an insulating material. The electric fence band (100) includes at least two essentially bare electric conductors located at a first distance from each other, which electric conductors form two conductor groups (110a, 110b). The system also comprises an electric fence device (105), which is arranged to generate a pulsed high voltage between the two conductor groups (110a, 110b) of the electric fence band (100), and at least two bypass cables (301a, 301b) for bypassing an obstacle (300) in the building. The bypass cables are intended to be fastened by their both ends to the conductor groups (110a, 110b) of the electric fence ban