ローカル パスが何かわかっている場合は、テストして力ずくで実行できます: (TODO: すべてを Unicode にします)
// Helper function to make a name unique.
std::string computername()
{
static std::string name = []() {
WCHAR buf[MAX_COMPUTERNAME_LENGTH];
DWORD len = MAX_COMPUTERNAME_LENGTH;
GetComputerNameEx(ComputerNameNetBIOS, buf, &len);
return std::string(buf, buf + len);
}();
return name;
}
int main()
{
std::string dir = "C:\\FindThisShare\\";
// First, create marker
std::string testfile = computername() + " 038D2B86-7459-417B-9179-90CEECC6EC9D.txt";
std::ofstream test(dir + testfile);
test << "This directory holds files from " << computername()
<< std::endl;
test.close();
// Next, find the UNC path holding it.
BYTE* buf;
DWORD numEntries;
NetShareEnum(nullptr, 1, &buf, MAX_PREFERRED_LENGTH, &numEntries,
&numEntries, nullptr);
auto data = reinterpret_cast<SHARE_INFO_1*>(buf);
std::string retval;
for (int i = 0; i != numEntries; ++i)
{
auto const& entry = data[i];
std::wstring tmp(entry.shi1_netname);
std::string share(tmp.begin(), tmp.end());
std::string uncdir = "\\\\" + computername() + "\\" + share + "\\";
if (PathFileExistsA((uncdir + testfile).c_str()))
{
printf("Exists");
}
}
remove((dir + testfile).c_str());
NetApiBufferFree(buf);
}