Using Biomart as mentioned by @poisonAlien probably is your best bet.
That said, you could also use BridgeDb. If I understand you correctly, essentially what you want to do is to map two different database IDs for human genes where the first is the HGNC name (used by NCBI as the gene name) and the other is the NCBI gene ID.
You could do that with a BridgeDb webservice call like:
http://webservice.bridgedb.org/Human/xrefs/H/PRKAR1A?dataSource=L
It asks for the ID in dataSource L (Entrez gene) for a human gene name from HGNC (identified as H).
Note that you would normally want to install the BridgeDb webservice locally, this only serves as an example.
Further information at http://webservice.bridgedb.org (also for a link to dataSource codes) and in this paper.