0

为了获取共享文件夹名称,我使用了以下代码,在这里我可以获取文件夹名称。但是我面临的问题是用户创建的共享文件夹也提供了一些额外的文件夹,我不知道如何防止程序隐藏那些不必要的文件夹名称。就像在我的情况下,我得到“cc_views”(用于clearcase)和“Users”文件夹,我想从我的文件夹列表中删除它们。

我写了以下代码,请帮助获得正确的输出。

 #ifndef UNICODE
    #define UNICODE
    #endif
    #include <windows.h>
    #include <stdio.h>
    #include <lm.h>
    #pragma comment(lib, "Netapi32.lib")
    #pragma comment(lib, "Advapi32.lib")

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

       switch(argc)
       {
       case 2:
          lpszServer = lpszArgv[1];
          break;
       default:
          printf("Usage: NetShareEnum <servername>\n");
          //return;
       }
       //
       // Print a report header.
       //
       printf("ShareFolderName\n");
   printf("---------------\n");
       //
       // Call the NetShareEnum function; specify level 502.
       //
       do // begin do
       {
          res = NetShareEnum ((LPSTR)lpszServer, 502, (LPBYTE *) &BufPtr, MAX_PREFERRED_LENGTH, &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++)
             {
                 LPCTSTR str = (LPCTSTR)p->shi502_remark;
                 if(!(lstrcmpi(str,L"Remote admin")==0 ||lstrcmpi(str, L"Remote IPC")==0 || lstrcmpi(str,L"Default share")==0)) //Help in removing from extra folder based on the remarks
                    printf("%-20S%\n",p->shi502_netname);
                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;
    }
4

1 回答 1

1

只需在此处继续添加要在列表中排除的值:

if(!(lstrcmpi(str,L"Remote admin")==0 ||
     lstrcmpi(str, L"Remote IPC")==0 || 
     lstrcmpi(str,L"Default share")==0 ||
     lstrcmpi(str,L"cc_views")==0 ||
     lstrcmpi(str,L"Users")==0))
       printf("%-20S%\n",p->shi502_netname);
于 2013-04-16T01:07:13.387 回答