We surveyed 81 dense molecular cores associated with regions of massive star formation and Sgr A in the 5_{05}-4_{04} and 10_{010}-9_{09} lines of HNCO. Line emission was detected towards 57 objects. Selected subsamples were also observed in other HNCO lines covering a frequency range from 22 to 461 GHz. HNCO lines from the K_{-1} = 2,3 ladders were detected in several sources. Towards Orion-KL, K_{-1} = 5 transitions with upper state energies E_u/k ~ 1100 and 1300 K could be observed. Five HNCO cores were mapped. The sources remain spatially unresolved at 220 and 461 GHz with beam sizes of 24 and 18, respectively. Typical HNCO abundances relative to H_2 as derived from a population diagram analysis are ~ 10^{-9}. The rotational temperatures reach ~ 500 K. The gas densities in regions of HNCO $K_{-1}=0$ emission should be n > 10^6 cm^{-3} and in regions of K_{-1}>0 emission about an order of magnitude higher even for radiative excitation. HNCO abundances are found to be enhanced in high-velocity gas. HNCO integrated line intensities correlate well with those of thermal SiO emission. This indicates a spatial coexistence of the two species and may hint at a common production mechanism, presumably based on shock chemistry.