REDMOND, Wash. – Microsoft (Nasdaq: MSFT) said Thursday that an accounting adjustment to reflect a weak online ad business led to its first quarterly loss in its 26 years as a public company.

The software company had warned that it was taking a $6.2 billion charge because its 2007 purchase of online ad service aQuantive hasn’t yielded the returns envisioned by management. The non-cash adjustment is something companies do when the value of their assets decline. Microsoft Corp. paid $6.3 billion for aQuantive, only to see rival Google Inc. expand its share of the online ad market.

The charge led to a $492 million loss in the April-June quarter, or 6 cents a share. That compares with earnings of $5.9 billion, or 69 cents, a year ago.

Revenue rose 4 percent to $18.06 billion.

Sales were shored up by companies pushing forward with planned upgrades to software that runs corporate computers, even while delaying other technology purchases amid weakness in the economy.

Business buying helped compensate for diminished demand from consumers who are awaiting the Oct. 26 release of Windows 8, the next version of Microsoft’s main operating system, or are opting for machines made by Apple Inc. and other competitors.

“Sixty percent of Windows revenue comes from the corporate market, and corporate is marching along on their Windows 7 upgrade,” said Mark Moerdler, an analyst at Sanford C. Bernstein & Co. in New York.

Microsoft shares rose in extended trading after the report. The stock had gained less than 1 percent to $30.67 at the close in New York. It fell 5.2 percent in the three months through the end of June, compared with a 3.3 percent drop for the Standard and Poor’s 500 Index.

Excluding the adjustment and the deferral of some revenue into the current quarter related to its launch of Windows 8, earnings came to 73 cents per share, beating the 62 cents per share expected by analysts polled by FactSet.

Although the earnings were higher than expected, analysts were looking for higher revenue at $18.15 billion.

(Bloomberg and The AP contributed to this report.)