获得本地共享目录列表

来源:互联网 发布:腾讯云搭建java 编辑:程序博客网 时间:2024/04/30 11:01

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

#pragma comment(lib,"Netapi32.lib")

void main( int argc, TCHAR *lpszArgv[ ])
{
   PSHARE_INFO_502 BufPtr,p;
   NET_API_STATUS res;
   LPTSTR   lpszServer = NULL;
   DWORD er=0,tr=0,resume=0, i;


   //
   // Print a report header.
   //
   printf("Share:              Local Path:                   Uses:   Descriptor:/n");
   printf("---------------------------------------------------------------------/n");
   //
   // Call the NetShareEnum function; specify level 502.
   //
   do // begin do
   {
      res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
      //
      // If the call succeeds,
      //
      if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
      {
         p=BufPtr;
         //
         // Loop through the entries;
         //  print retrieved data.
         //
         for(i=1;i<=er;i++)
         {
            printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses);
            //
            // Validate the value of the
            //  shi502_security_descriptor member.
            //
            if (IsValidSecurityDescriptor(p->shi502_security_descriptor))
               printf("Yes/n");
            else
               printf("No/n");
            p++;
         }
         //
         // Free the allocated buffer.
         //
         NetApiBufferFree(BufPtr);
      }
      else
         printf("Error: %ld/n",res);
   }
   // Continue to call NetShareEnum while
   //  there are more entries.
   //
   while (res==ERROR_MORE_DATA); // end do
   return;
}

原创粉丝点击