A 24-year-old Baltimore man was sentenced in D.C. Superior Court yesterday to serve 38 years to life in prison in connection with four armed robberies in which he shot three people, seriously wounding two of them.

James Edward Hayes, who already was serving a 2 to 8-year sentence for possession of a sawed-off shotgun, was given the new sentence for his involvement in holdups at two McDonald's restaurants and a service station on Jan. 24, 1979, and at a roller-skating rink the following day. He was sentenced by D.C. Superior Court Judge Annice Wagner.

According to police investigators, Hayes and two Baltimore teen-agers, who later pleaded guilty in the cases and turned prosecution witnesses, first robbed the McDonald's at 1603 Good Hope Rd. Se of a small amount of money and stole a restaurant guard's revolver.

Fifteen minutes later, the three suspects robbed the McDonald's at 1164 Bladensburg Rd. NE, police said, and Hayes shot the manager who did not respond quickly enough to the robbers' demands. The manager was not seriously wounded.

Shortly after the second McDonald's robbery, police said, Hayes shot Theresa Hawkins, 30, as she was sitting in a car at a service station while a friend bought a soft drink. Police later learned that Hayes thought the woman and her friend had recognized the robbers' getaway car as stolen, which it had been.

Hawkins was shot in the upper right arm and has permanently lost partial use of that arm.

In the fourth crime, at the National Roller Skating Rink, 1661 Kalorama Rd. NW, Hayes shot William Boulware, a 14-year-old skater, in the hip, police said.

The shooting hospitalized the youth for seven months, left his relatives with a $70,000 medical bill, and forces him to wear a brace and walk with a cane.