The governor on Monday 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 that he was a danger to himself.

But 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.

"Whether that treatment is to be provided in an inpatient or outpatient facility is of no moment," Kaine said.

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

"His lie on the form would have been caught," had the order been in place before Cho attempted 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 or hobbyists, and gun shows — vast firearms bazaars 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 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. After the report is added to Virginia's state police database, it becomes part of a federal database that gun dealers nationwide use.

Cho, a 23-year-old Virginia Tech senior described as a troubled loner, bought his guns legally through gun shops before gunning down 32 people on campus, then killing himself.

No motive has been established for his rampage.