A search has been performed for long-lived particles that have stopped in the CMS detector, during 7TeV proton-proton operations of the CERN LHC. The existence of such particles could be inferred from observation of their decays when there were no proton-proton collisions in the CMS detector, namely during gaps between LHC beam crossings. Using a data set in which CMS recorded an integrated luminosity of 4.0 fb(-1), and a search interval corresponding to 246 hours of trigger live time, 12 events are observed, with a mean background prediction of 8.6 +/- 2.4 events. Limits are presented at 95% confidence level on long-lived gluino and stop production, over 13 orders of magnitude of particle lifetime. Assuming the "cloud model" of R-hadron interactions, a gluino with mass below 640 GeV and a stop with mass below 340 GeV are excluded, for lifetimes between 10 mu s and 1000s.