We propose a method of constructing a gauge invariant canonical formulation for non-gauge classical theory which depends on a set of parameters. Requirement of closure for algebra of operators generating quantum gauge transformations leads to restrictions on parameters of the theory. This approach is then applied for illustration to bosonic string theory coupled to background tachyonic field. It is shown that within the proposed canonical formulation the known mass-shell condition for tachyon is produced.