I am trying to programmatically retrieve the network path where the C++ executable is stored. For clarity, when I say network path, I mean the path retrieved in Windows manually by: 'right clicking the folder', 'choosing properties', and 'selecting the sharing tab'. An example of this path can be seen here.
Does anyone know how to adapt my below code to retrieve the network path (as specified above) rather than the local path?
Here is minimal reproducing code:
#include <iostream>
#include <Windows.h>
#include <sstream>
#include <shlwapi.h>
#include <string>
#pragma comment(lib, "netapi32.lib")
#pragma comment(lib, "Shlwapi.lib")
using namespace std;
std::wstring GetExecutableDirectory()
{
// Get the full path to the executable file
wchar_t buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
// Remove the file name from the path
PathRemoveFileSpec(buffer);
return std::wstring(buffer);
}
int main()
{
std::wstring localPath = GetExecutableDirectory();
// SOME CODE IN HERE TO GET THE NETWORK-SHARE PATH
//....
wcout << L"Local path: " << localPath << endl;
wcout << L"Network-share path: ";
return 0;
}
I use Visual Studio 2022 as my coding environment, and my OS is Windows 11. For context, I am new to this language and still learning.
I've tried several things to troubleshoot (but had no luck), including:
trying the WNetGetUniversalName function, as implemented by @Stefan.
I also asked a previous question related to this that can be found herechecking the local path exists (it does, and is found by the sample code)
checking the sharing permissions within the local path folder (they are set to share with everyone)
running the C++ code directly from the executable (instead of the VS2022 debugger)
Thank you in advance.