't Hooft's construction of free energy, electric and magnetic fluxes,
and of the partition function with twisted boundary conditions, is ext
ended to the case of N = 4 supersymmetric Yang-Mills theories based on
arbitrary compact, simple Lie groups. The transformation of the fluxe
s and the free energy under S-duality is presented, We consider the pa
rtition function of N = 4 for a particular choice of boundary conditio
ns, and compute exactly its leading infrared divergence, We verify tha
t this partition function obeys the transformation laws required by S-
duality. This provides independent evidence in favor of S-duality in N
= 4 theories.