Most times they are not trying to gain access to your site. There might be a few instances of this, but it's very rare. If someone is trying to get into your site they aren't going to leave notes like that behind.
The main purpose of comments like this is SEO. People post commetns like this, which are done through automated systems 99% of the time, to get a backlink from your site to their site to help their SEO rankings. You will see that they will almost always include a URL in the comment, or with their name. This gets them a link from your site to their site, and helps to boost their rankings.
As you've seen, it's normally very easy to pick the automated SPAM ones. You can either go through and delete all of these yourself, or install an nti-SPAM module like Akismet that can help with these sort of issues.