This question gets into an interesting topic. A short way to respond is that if you have a definitive answer about what brings in more and better recruits, there's a Lieutenant General and a mad scientist who might show up on your doorstep, since the Department of Defense would really like to talk with you as they're not all that sure about what does so either.
So let's go all the way back. Direct military involvement in film making starts in 1927 with Wings in providing assistance with the various dogfights. This continues and grows throughout the interwar period and World War II to what's been the standard since the 1950s; each branch has a military liaison office in Hollywood, coordinating with producers directly, as well as the DoD office overseeing everything that was established by Don Baruch - son of the legendary political financier Bernard Baruch - to offer often less-than-subtle 'suggestions' to change scripts to those more reflective of what the military wanted to portray at that particular time.
This has provided significant leverage to the DoD since it can save significant production costs for films and TV to use DoD assets for either free or vastly reduced operational cost. Some of the changes requested have been pretty reasonable, such as when potential allies were presented as enemies or when basic facts are simply wrong. More often, they've been used to polish the image of the military in ways that can be a little problematic. At times, though, they've ventured into outright absurdity, such as when Kevin Costner was filming Thirteen Days and the liaison demanded he present Curtis LeMay in a less controversial light and remove Major Rudolph Anderson's U2 being shot down, despite many of LeMay's lines in the film having been literally transcribed from the Kennedy tapes and Anderson being awarded the Air Force Cross.
Plentiful films just outright skipped even the attempt to get DoD cooperation, and even some famous ones that did still ran the gauntlet; there was significant DoD and Navy opposition to The Caine Mutiny until Chief of Naval Operations William Fechteler overrode it, with the great line about how Herman Wouk had somehow managed to have seen "all the screwballs I have known in my 30 years in the navy" in 2 years as a reserve officer and then put them all together on one ship. (Worth a watch is a great discussion by the Naval Historical Foundation about that movie's continuing importance for professional officers, which can be found here.)
This hot-and-cold relationship continues in the 1950s and 1960s - where the DoD cooperates with Mickey Mouse and Lassie to try to encourage teenagers to enlist or apply to the service academies (which as strange as it may seem now, at various times in their history have had significant problems getting and keeping quality recruits) - but it comes to a boil in the early 1970s, when the draft has become incredibly unpopular. The Army in particular realizes that it is in real trouble; even with the draft, it not only is having problems maintaining a force in a hostile public environment, but is losing in competition against other services as well.
It starts trying to sell itself using more modern techniques; as early as 1971, a report by its ad agency starts denoting recruits as "the market" and the Army as the "product." The sea change is in 1973, when after several years of debate, all branches go volunteer as an underlying force structure. For the Army, it starts this new era by reaching out with such ads titled like "We care more about how you think than how you cut your hair" (e.g. how long your hair is) and to women, "[Being in a dead end job isn't] very likely to take you anywhere...we have over 400 jobs in fields that offer you a future" and that they can "date, even marry."
That's when the DoD started really drilling down into what potential recruits were interested in well beyond what their ad agencies were telling them. It establishes the Youth Attitude Tracking Study (the YATS), which is a robust annual telephone survey of over 10,000 18-24 year olds conducted from 1975-1999 about what is working in recruiting, how young people see the military, and what young people expect if they join up. (It has since been replaced with the Youth Poll, Futures Survey, and Influencer Survey. One answer that's been consistent over the years is where potential recruits get their impressions of the military from; even in the 1990s family members and friends who had some military experience had already dropped to 30%. Instead, they learned far more from TVs and movies, at which point Gen X had picked up impressions from Full Metal Jacket, Platoon, A Few Good Men, Forrest Gump, MASH...and Top Gun.
Top Gun deserves a specific mention here since there's a widely quoted claim in popular and even some academic work that it increased inquiries for naval aviator recruits by 500% and Navy recruiters were setting up booths outside theaters during showings of the film. If you track this down, though, there are a couple of issues. First, the claim comes from a Top Gun producer rather than being stated by the military itself, which makes the source somewhat shaky. In fact, a 1986 LA Times article that interviewed said recruiters at the time mentions an increase of some sort but noted something else - that those who were talking to them as a result were on the margins of the qualifications for the program:
"Two groups I can identify (as having increased interest) are individuals who have applied in the past and were turned down or dropped out of Aviation Officers Training School, and individuals who are approaching the maximum age limit (to apply)...on the other end of the spectrum, we’ve seen a general increase in interest in young men who don’t yet qualify for the program, and I have to attribute that to ‘Top Gun’ also."
Second, what is not mentioned in any of this is that the military has never really had all that much of a problem finding people interested in being pilots, naval or otherwise. It's the qualifications that are a pain - such as 20/20 vision, which if you don't have but you're still otherwise qualified they were happy to shunt you over as a radar intercept officer, now the WSOs - whether or not you can make it through the various schools and physical requirements like g-force testing, and most critically of all, retaining them after their service commitment expires. Pilots are in tremendous demand in the private sector, and the multiple millions of dollars worth of training they receive at taxpayer expense mean that commercial airlines are extremely aggressive in their recruiting of them. (The expense of taxpayer training has even been used as one basis of a court injunction against pilots during a strike.)
It's all the harder-to-fill other jobs in the military that may benefit from this, but that data is a whole lot trickier to wrangle. One good story on the presumed value comes from a deal that a producer tried to get out of the DoD when he owed it several million for assets used in Flight of the Intruder, where an upcoming joint video release was touted as:
"The demographics for (the VHS release of Red October and Flight of the Intruder) show that we will have a strong percentage of viewers in the 15 to 19 age group, which presumably would be the correct target audience for the Navy...with a minimum of 60 million unduplicated impressions, the recruiting benefits for the video release will be of major significance, with particular emphasis on the high priority targets concerning recruits for nuclear power and aviation roles in the Navy."
In exchange for forgiving $2 million of debt, he offered to place a 90 second Navy recruitment ad at the beginning of each tape; the Navy's ad agency put the kibosh on it estimating that on television buy value alone it was worth at most $100,000, and that since both movies served as effective recruiting ads anyway, why bother?
So, no, there is no real definitive answer as to if Stargate or Band of Brothers or Top Gun helped out recruiting; given how much impressions come from TV and movies versus family now, they probably did. However, if your recruiter decides to pull the classic MEPS bait and switch of the MOS you were promised "not being available" and turning you into an MP right before you took your oath of enlistment, not as much.
On some things, the Air Force certainly did try to make Stargate's depiction of military culture as realistic as possible to provide a more accurate image for potential recruits. Two examples: grooming standards got enforced for those wearing uniforms and relationships were carefully looked at as to whether or not they'd be allowed. There's also a good story about how Richard Dean Anderson had a slightly nervous conversation with the Chief of Staff of the Air Force when he cameo'd on the show, asking him if his portrayal of O'Neill was too over the top and if there were any colonels in the Air Force like him. The CoS's response surprised him: he interrupted him in the middle of the question and said "Yes, and worse. There are plenty of colonels who are a pain in the ass to manage. Keep it up."
Sources: The Army in the Marketplace: Recruiting an All-Volunteer Force (Bailey, 2007), Guts and Glory: The Making of the American Military Image in Film Paperback (Suid, 2002), Operation Hollywood (Robb, 2004)