I've been in the army or in Federal Security for nearly my entire adult life. The answer to this problem is neither cheap nor easy, but there is an answer. Schools are a "soft" target and that must change...these random shootings, horrific as they are, are nothing compared to the threat of an organized attack on school.
We need to follow the Israeli model of hardening schools with physical barriers and having staff/teachers be armed and trained to defend their students. Gun control will do nothing...worse than nothing. Putting an armed security guard/resource officer on site will also be of minimal value...they themselves would generally be easy to take out and their reliability/skill would be very poor...and one person cannot defend a site as large as the average elementary school.
What 's needed are multiple layers of protection...a layered defense with a number of barriers that can impede a shooter attempting to breach an education facility.
A school must be protected with three primary layers of security...the first is physical structure that is difficult to penetrate (locked steel doors that allow regress but not access...and yes...barred windows). Second, primary entrances must be controlled and monitored with persons in a protected area "allowing" controlled access only to known/cleared persons and students. Finally, most if not all teachers must be armed, trained, and they must practice responding to breach situations.
All of these elements are achievable...but we must as a nation have the will to implement such changes. If we don't do so...or if we sit around trying to implement idiotic gun control measures that are insufficient AND generally unenforceable...these attacks will continue to happen.