The big problem with this idea is the huge difference in cross-sectional area between the larvae and the tree.
Wood is a wonderful electrical insulator. Even damp wood only has a specific conductivity of around 10^-4 S/m (Siemens per meter).
Let's assume that you have a 10kV voltage source, which is already way more than enough to kill cattle if the current capability is high enough. Let's also assume a cylindrical tree with 20cm diameter and 2m length. The cross-sectional area of the tree is 1257cm² (0.1257m²). To get the tree's conductance, we multiply the specific conductivity with the tree's cross-sectional area and divide by its length: G = 10^-4 S/m * 0.1257m² / 2m = 6.285µS (microsiemens).
To get the total current flowing through the tree, we can multiply the voltage and conductance: Itree = 10kV * 6.285µS = 62.85mA.
Let's also assume that you have some very large larvae in the tree with a cross-sectional area of 4cm². Given that the larvae are small compared to the size of the tree, the current will divide between the larva and the surrounding wood roughly in proportion to their area: The larva will get a current share of p = 4cm² / 1257cm² = 0.0032 = 0.32%.
This means the larva will experience an electrical current Ilarva = Itree * p = 62.85mA * 0.0032 = 0.2mA = 200µA.
The larva isn't even going to notice this. The tree's wood is very effective at protecting the larvae within it from electricity.
On the other hand, the tree is already experiencing P = Itree * U = 62.85mA * 10kV = 628.5W of power being dissipated within it, which will kill it quite quickly.
TL;DR: Tree dies, larvae live.
You could of course increase the voltage even further, but...