RICHMOND, Va. - The governor yesterday closed the loophole in state law that allowed the Virginia Tech gunman to buy weapons despite a court ruling that he was a threat and needed psychiatric counseling.

Gov. Timothy M. Kaine issued an executive order requiring that a database of people banned from buying guns include the name of anyone who is found to be dangerous and ordered to get involuntary mental-health treatment.

Seung-Hui Cho was told to get counseling in 2005 after a judge ruled he could hurt himself.

Because Cho was treated as an outpatient and never committed to a mental-health hospital, the court's decision was not entered into the database, which gun dealers must check before selling a weapon.

Cho did not disclose his mental-health problems or the court-ordered treatment in a form he filed before buying the guns.

"His lie on the form would have been caught," had the order been in place before Cho tried to buy the guns, Kaine said.

But it would not prevent Cho from acquiring guns by several other means that require no background check in Virginia, including buy-and-trade publications, individual transactions among gun collectors, and gun shows - where scores of people sell or swap firearms.

Legislation that would also subject firearms sales at gun shows to instant background checks is introduced annually in Virginia, and just as often it dies without reaching a floor vote in the General Assembly.

Kaine, a Democrat, has said that he expects new support for the legislation this year and that he would support it, as he has in the past.

The executive order does not apply to people who seek mental-health care of their own will.