Get server name from UNC path

Is there an api on windows that extract the server name from the UNC path? (\\ server \ share)
Or do I need to make my own?
I found PathStripToRoot, but that doesn't do the trick.

+1


a source to share


4 answers


I don't know the Win32 API for parsing a UNC path; however you should check:

  • \\computername\share

  • \\?\UNC\computername\share

    (people use this to access long paths> 260 characters)
  • You can also handle this case: smb://computername/share

    and this casehostname:/directorypath/resource



Read more here

+1


a source


This is untested, but perhaps a combination of PathIsUNC () and PathFindNextComponent () will do the trick.



+1


a source


I don't know if there is a specific API for this, I would just do some simple string handling myself (skip "\\" or return zero, find the next or end of the string and return a substring), perhaps calling PathIsUNC () first

0


a source


If you get the data in plain text you will be able to parse it with a simple regex, not sure which language you are using, but I try to use perk for quick searches like this. Suppose you have a large document containing multiple lines containing one path per line, which you can search in \\ Ie m / \\\\ ([0-9] [0-9] [0-9] \ . (repeat 3 times, of course without triggering the IP address requirements, you may need to change the first one) then \\)? To make it optional and include a trailing slash, and finally (. *) \\ / ig is rough, but should do the trick, and the pathname must be in $ 2 to use!

I hope this was clear enough!

0


a source







All Articles