Context. Cyanopolyynes (HC2n+1 N, n = 1,2,3), which are the linear carbon chain molecules, are precursors for the prebiotic synthesis of simple amino acids. They are important for understanding prebiotic chemistry and may be good tracers of the star formation sequence. Aims. We aim to search for cyanopolyynes in high-mass star-forming regions (HMSFRs) at possibly different evolutionary stages, investigate the evolution of HC3N and its relation with shock tracers, and detect the existence of HC5N and HC7N in HMSFRs with a formed protostar. Methods. We carried out a cyanopolyyne line survey towards a large sample of HMSFRs using the Shanghai Tian Ma 65 m Radio Telescope (TMRT). Our sample consisted of 123 targets taken from the TMRT C band line survey. It included three kinds of sources, namely those with detection of the 6.7 GHz CH3OH maser alone, with detection of the radio recombination line (RRL) alone, and with detection of both (hereafter referred to as Maser-only, RRL-only, and Maser-RRL sources, respectively). For our sample with detection of cyanopolyynes, their column densities were derived using the rotational temperature measured from the NH3 lines. We constructed and fitted the far-infrared (FIR) spectral energy distributions (SED; obtained from the Herschel FIR data and the Atacama Pathfinder Experiment data at 870 µm) of our HC3N sources. Moreover, by analysing the relation between HC3N and other shock tracers, we also investigate whether HC3N is a good tracer of shocks. Results. We detected HC3N in 38 sources, HC5N in 11 sources, and HC7N in G24.790+0.084, with the highest detection rate being found for Maser-RRL sources and a very low detection rate found for RRL-only sources. The mean column density of HC3N was found to be (1.75 ± 0.42) × 1013, (2.84 ± 0.47) × 1013, and (0.82 ± 0.15) × 1013 cm−2 for Maser-only, Maser-RRL, and RRL-only sources, respectively. Based on a fit of the FIR SED, we derive their dust temperatures, H2 column densities, and abundances of cyanopolyynes relative to H2. The mean relative abundance of HC3N was found to be (1.22 ± 0.52) × 10−10 for Maser-only, (5.40 ± 1.45) × 10−10 for Maser-RRL, and (1.65 ± 1.50) × 10−10 for RRL-only sources, respectively. Conclusions. The detection rate, the column density, and the relative abundance of HC3N increase from Maser-only to Maser-RRL sources and decrease from Maser-RRL to RRL-only sources. This trend is consistent with the proposed evolutionary trend of HC3N under the assumption that our Maser-only, Maser-RRL, and RRL-only sources correspond to massive young stellar objects, ultracompact H ii regions, and normal classical H ii regions, respectively. Our detections enlarge the sample of HC3N in HMSFRs and support the idea that unsaturated complex organic molecules can exist in HMSFRs with a formed protostar. Furthermore, a statistical analysis of the integrated line intensity and column density of HC3N and shock-tracing molecules (SiO, H2CO) enabled us to find positive correlations between them. This suggests that HC3N may be another tracer of shocks, and should therefore be the subject of further observations and corresponding chemical simulations. Our results indirectly support the idea that the neutral-neutral reaction between C2H2 and CN is the dominant formation pathway of HC3N.