tags:

views:

682

answers:

1

I would like to programmatically add to Windows a name / IP association so that this name can be resolved locally. This does not have to be persisted between reboots.

The only way I now is to add an entry to the "hosts" file, but this feels hacky especially since I would like to automate this.

Is there any way to do this using a command-line tool or a Win32 API? Perhaps by addind an entry to Windows DNS cache or something similar?

Oh, and please state if this solution is Vista-compatible.

Regards.

Edit : Thanks, guy. Sadly, all of your answers indeed involve DNS or other servers. I was looking for a purely local solution which would work on a "standard" Windows installation. Such a thing does not seem to exist, though.

A: 

This page lists a bunch of scripts for doing various things with the DNS service, including adding a name to it. This seems to be part of the Windows Management Instrumentation system, which I'm afraid I don't know anything about.

EDIT: There is also this function, which says it can add records to the DNS. Not sure if that means that it actually modifies the DNS server's state, or if it talks about the local resolver. It also requires Windows 2000 Server or greater, so it might be too narrow.

unwind
I'm afraid the linked scripts are for modifying the DNS records of the server. This is usable for the question but would involve exposing the DNS server to modification by anyone you wish to be able to add records.... it would also make the name->IP mapping global rather than local to the machine
ShuggyCoUk
If you run a local DNS server on each machine this becomes possible but I don't know if the local servers will respond to WMI. see http://www.simpledns.com/kb.aspx?kbid=1128 for a product that might work
ShuggyCoUk
Ah, right. That's a bit of overkill.
unwind
ah yes, it has an API http://www.simpledns.com/help/api/ just not a WMI one
ShuggyCoUk
I accept your answer as the closest to what can be achieved, considering that what I asked for those not seem to be achievable on a standard Windows install.
Tanelorn