Vice President Dick Cheney used the setting of an aircraft carrier in the Persian Gulf to deliver a stern message to Iran today, warning that the United States would not allow Iran to obtain nuclear weapons or gain the upper hand in the Middle East.

“With two carrier strike groups in the Gulf, we’re sending clear messages to friends and adversaries alike,” he said, in a speech on board the U.S.S. John C. Stennis.

The United States “will stand with others to prevent Iran from gaining nuclear weapons and dominating this region,” he said.

The aircraft carrier was about 20 miles off the coast of Abu Dhabi, one of the United Arab Emirates, according to a pool report provided by journalists traveling with Mr. Cheney. Mr. Cheney traveled to the Emirates following a two-day visit to Iraq, and will be making other stops in the Middle East on his week-long trip.

Mr. Cheney’s message seemed particularly pointed because, according to the pool report and the Associated Press, the president of Iran, Mahmoud Ahmadinejad, is scheduled to visit Abu Dhabi himself in the next few days.

Mr. Cheney said today that the United States was determined, in the event of any crises in the region, to keep the sea lanes of the Gulf open.

His speech to American service members on board the carrier also seemed intended to reassure them that a strong American presence would be maintained in the region for some time.

“I want you to know that the American people will not support a policy of retreat,” Mr. Cheney said. “We want to complete the mission, we want to get it done right, and then we want to return home with honor.”

On Thursday in Iraq, Mr. Cheney spoke to American troops stationed near Saddam Hussein’s birthplace, Tikrit, telling them in somber tones that they still had a tough fight ahead of them.

His assessment stood in stark contrast to the one he made two years ago, when he declared in an interview with CNN that the insurgency in Iraq was in its “last throes.”

The United States remains at odds with Iran over its nuclear program, which Iran says is peaceful, but which America and its Western allies say is intended to build weapons. The Bush administration has also expressed concerns about Iranian involvement in Iraq; officials have said that weapons are being smuggled into Iraq from Iran and that the insurgents who assemble and placing bombs in Iraq may be getting training in Iran. The Iranian government denies sponsoring or encouraging terrorism.

Mr. Cheney visited the U.S.S. John C. Stennis before, in March 2002, at a time when he was trying to build support for the invasion of Iraq, the A.P. noted.

Today, standing in front of five F-18 Super Hornet warplanes and a huge American flag on the hangar deck of the carrier, Mr. Cheney spoke to some 3,500 service members, according to the A.P. He sounded a hard line, saying the United States must hold firm in Iraq and confront Iran if necessary, the agency reported.

His tour of the Middle East will also include visits to Saudi Arabia and Jordan.