Hi everyone,
as the heading already says i want to check whether a folder is a network share or not.
So far i tried to achieve this by reading the file attributes but that did not lead to the right solution.
If anyone here knows how to do this please reply.

I assume you are talking about MS-Windows operating systems. If not, then ignore this.

maybe the example in this link and this will help you. It shows you how to mount a network drive. If WNetAddConnection2() fails and returns ERROR_ALREADY_ASSIGNED then the drive is already mounted. Also make sure to read the remarks at the bottom of the page.

maybe the example in this link and this will help you. It shows you how to mount a network drive. If WNetAddConnection2() fails and returns ERROR_ALREADY_ASSIGNED then the drive is already mounted. Also make sure to read the remarks at the bottom of the page.

No.
You must use SH api.

After looking around i decided to use NetShareEnum but encountered a problem there.
I tried the following code but it only displays the first characters of each share.

#include <iostream>
#include <windows.h>
#include <lm.h>

int main()
{
	DWORD dwStatus, dwSharesRead, dwTotalShares;
                LPSHARE_INFO_2 pShareBuffer, pShareTemp;

	dwStatus = NetShareEnum(NULL, 2, (LPBYTE *)&pShareBuffer,
                MAX_PREFERRED_LENGTH, &dwSharesRead, &dwTotalShares, NULL);

	pShareTemp = pShareBuffer;

	while (dwSharesRead > 0)
	{
		std::cout << pShareTemp->shi2_netname;
		std::cout << pShareTemp->shi2_path << std::endl;

		dwSharesRead--;
		pShareTemp++;
	}
	NetApiBufferFree(pShareBuffer);

	system("pause");
	return 0;
}

I would be grateful for any hint.

It's a UNICODE string. Use WideCharToMiultiByte to convert share name to ordinar string.
May be better try NetShareGetInfo?
Apropos, "No special group membership is required for level 0 or level 1 calls" only...

Eventually i got it working using edited code from an MS example. Although it works i don't see a major difference to the code above.
But nevertheless it works and so i will mark the thread as solved thanks for your help everyone.

#include <windows.h>
#include <stdio.h>
#include <lm.h>

int main()
{
   PSHARE_INFO_502 BufPtr, p;
   NET_API_STATUS res;
   LPTSTR   lpszServer = NULL;
   DWORD er = 0,tr = 0,resume = 0, i;
   
   do
   {
      res = NetShareEnum(lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);

      if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
      {
         p = BufPtr;

         for(i = 1; i <= er; i++)
         {
			 printf("%S\t\t%S\n", p->shi502_netname, p->shi502_path);
			 p++;
         }

         NetApiBufferFree(BufPtr);
      }
      else 
         printf("Error: %ld\n", res);
   }
   while(res == ERROR_MORE_DATA);

   system("pause");
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.