2

I have a funny situation. I am sitting on a computer on which there is a shared folder, say, "My_Folder". So, I can access it using the address "\My_Box\My_Folder".

Now, if I write a small tool in C#, I can convert the "\My_Box\My_Folder" to "C:\My_Folder" which is its physically location.

The funny thing is that I don't know how to find the physically location of "My_Box\My_Folder" without my program ... And it's actually one of my friend's problem.

So if anyone knows how to find the local path from a network path with some simple basic Windows commands/operations (either Winxp, 2000, vista, 7, ...), please let me know.

Thanks, Pete.

pete
  • 93
  • 1
  • 5

1 Answers1

2

If all you need is a command line tool that will provide this information then you can simply use the net share command that’s built into Windows.

If you need to do it programmatically you can use the NetShareGetInfo function. The following example shows how to use it to query the path for \\localhost\share in C++.

#include <windows.h>
#include <lm.h>
#pragma comment (lib, "netapi32.lib")

#include <iostream>
using namespace std;

int main()
{
    BYTE * buffer = nullptr;

    auto error = NetShareGetInfo(nullptr, // local computer
                                 L"share",
                                 2, // level
                                 &buffer);

    if (ERROR_SUCCESS == error)
    {
        auto info = reinterpret_cast<SHARE_INFO_2 *>(buffer);

        wcout << info->shi2_path << endl;
    }

    if (buffer)
    {
        NetApiBufferFree(buffer);
    }
}

I would wrap the buffer in a class and call NetApiBufferFree from its destructor but that’s up to you.

Kenny Kerr
  • 3,015
  • 15
  • 18