A non-gauge dynamical system depending on parameters is considered. It is shown that these parameters can have such values that corresponding canonically quantized theory will be gauge invariant. The equations allowing to find these values of parameters are derived. The prescription under consideration is applied to obtaining the equation of motion for tachyon background field in closed bosonic string theory.