c++windows-xpnetwork-programmingwindows-nt

In C++/Windows how do I get the network name of the computer I'm on?


In a C++ Windows (XP and NT, if it makes a difference) application I'm working on, I need to get the network name associated with the computer the code is executing on, so that I can convert local filenames from C:\filename.ext to \\network_name\C$\filename.ext. How would I do this?

Alternatively, if there's a function that will just do the conversion I described, that would be even better. I looked into WNetGetUniversalName, but that doesn't seem to work with local (C drive) files.


Solution

  • You'll want Win32's GetComputerName:

    http://msdn.microsoft.com/en-us/library/ms724295(VS.85).aspx