Sandy, Utah - GARY D. KENNEDY, a 52-year-old former chief executive of a software company, was sitting on a black leather chair in his home office here in Sandy, an affluent suburb of Salt Lake City, beneath a painted portrait of his family. It was 1:15 p.m. on Dec. 15, 2005: he remembers it vividly. His wife, Jane, was standing over the fax machine when she noticed a strange expression on her husband's face. "What is it?" she asked.

Mr. Kennedy hung up the phone, looked up, and told her that the government, which had pursued a securities fraud case against him for more than five years, had decided to drop the charges.

Jane Kennedy, usually a poised and determined woman, collapsed and wept. "It was the first time I'd let myself acknowledge what had happened to us, the hell we had been through," she said.

It was a remarkable moment, not just because Mr. Kennedy had fought the Securities and Exchange Commission for years, but because he had won, just weeks before his trial was set to begin in Salt Lake.

For wealthy, high-profile executives under scrutiny, fighting the government is nothing new: consider Maurice R. Greenberg, the former chief at American International Group; Richard A. Grasso, the former head of the New York Stock Exchange; or Kenneth L. Lay and Jeffrey K. Skilling of Enron. But few executives at small and midsize companies -- executives whose names are unknown in American living rooms and who thrive on work in public companies -- opt for war. The costs, the risks and the personal consequences are too great.

Indeed, soon after the S.E.C. sued TenFold, Mr. Kennedy's software development company, along with him and three other executives in 2002 for accounting and disclosure issues, the company and its board of directors quickly settled.

By the fall of 2005, two of the three executives named with Mr. Kennedy had also chosen to settle, and charges against the third were dropped. When the S.E.C. decided not to take its case against Mr. Kennedy to trial, it also backed down on the cases against the others.

Mr. Kennedy's battle was driven by his fierce conviction, his deep religious faith -- and, by his own admission, a stroke of luck. Caught up in a period of unprecedented and egregious corporate fraud and a technology sector that seemed doomed, Mr. Kennedy was at the wrong place at the wrong time -- an almost hopelessly honest, accountable chief executive among a world of angry investors, defensive regulators and an unforgiving bureaucracy.

And while the decision ultimately went his way, it came at a price. Mr. Kennedy said he felt he was abandoned by many friends, business associates and members of the Mormon community in which he had served as a church bishop and a mission president. He said he was no longer as trusting of others as he once was.

He said he was reluctant to sit on the board of any public company, convinced that the S.E.C. would come after the company as retribution toward him. His patience has eroded, he says. "You don't get your reputation back," he said quietly.

Mrs. Kennedy, citing the costs of the fight, including lawyers' fees and other costs covered by insurance, adds: "Five years, $30 million and a ruined company. It's just sad."

BORN and raised in Randolph, Utah, a ranching community of fewer than 500 people about 75 miles northeast of Salt Lake City, Mr. Kennedy was the son of a miner and a grocery store cashier. At 18, he entered the University of Utah but interrupted his education to do three years of missionary work in Brazil. After graduating from the university, he went to the Kellogg School of Management at Northwestern University.

With a freshly minted M.B.A., he landed at Intel, then a small company, in 1980. He said his time there was most influential in shaping his thinking on business, but he left for a startup software company called Oracle after a church friend introduced him to its founder, Lawrence J. Ellison. "I was absolutely impressed with this guy," Mr. Kennedy says of Mr. Ellison. He was among the first dozen professional employees hired.

In the early days, Mr. Ellison would stop by to play basketball and eat dinner with the Kennedys. During the less than a decade when he was at Oracle, sales soared from $1 million to almost $1 billion. But Mr. Kennedy said he grew frustrated with Mr. Ellison's infamous temper, and he opted to leave in 1990. "Working for Larry directly is a strange experience," Mr. Kennedy says. "He's a mercurial guy." (Mr. Kennedy says they remain cordial; Mr. Ellison didn't return a call for comment.)

After Mr. Kennedy returned from a three-year stint as a Mormon mission president in Brazil, a former Oracle colleague, Jeff Walker, asked him to run TenFold, a software company Mr. Walker had founded in 1993. "Gary was one of the best -- maybe the best -- sales executives in the software industry," Mr. Walker said.

Friends warned Mr. Kennedy about returning to the egos and money of Silicon Valley. But Mr. Kennedy said he was intrigued by the company's business plan, which was to create software applications that were more tailored to clients' specific needs than off-the-shelf software, but not so customized as to make clients captive to the program designer.

The secret lay in technology that TenFold called the Universal Application, which the company said would let it build software solutions 10 times faster than other software companies. Such a plan was key to growth companies seeking to build agile software that could be shaped around fast-changing industries.

Mr. Kennedy joined in 1996, when revenue was $3 million; revenue soared to $92.4 million in 1999. Clients included Allstate, Abbey National, SkyTel and Barclays Global Investors. In May 1999, Goldman Sachs took TenFold public at $17 a share. By March 2000, carried by the momentum of the tech boom, TenFold's stock price rocketed to $70.

Then the bubble burst, and TenFold's business model followed suit. The company lost more than half of the deals it had expected to close in the second quarter -- almost all dot-com companies -- and it missed its second-quarter earnings estimates. The stock plummeted to a low of $1.06 that year.

The earthquake that hit the company revealed deeper problems: TenFold was failing to meet its deadlines. Companies changed their product demands and TenFold had overextended itself. Legal problems were also brewing. The S.E.C., apparently tipped off by an anonymous letter, started inquiring about allegations made in the letter that TenFold had improperly accounted for a transaction and bribed a company with shares from its initial public offering to accelerate other revenue.