大家好,我最近在工作中需要使用WindowsAPI的Net Functions的哦一系列函数。由于英语阅读能力比较差,对于MSDN的东西只是一知半解。在编码过程中,一直无法正确使用诸如"NetShareGetInfo"以及"NetShareEnum"等一系列函数的使用方法。希望向各位大虾请教一下,如果能够提供比较详尽的源代码就更好了。多谢大家了。

解决方案 »

  1.   

    #define UNICODE
    #include <windows.h>
    #include <stdio.h>
    #include <lm.h>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("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;
    }
      

  2.   

    谢谢大家的支持。还希望了解函数NetShareGetInfo的使用方法。最好大部分Net Functions族里面的函数都想了解一下。
      

  3.   

    www.sysinternals.com上,有个开源的工具,ShareEnum,用到了你说的函数,看看它的示例代码吧。
      

  4.   

    谢谢DentistryDoctor的帮助。那个开源的东西已经下载了,我把相关的代码提取出来测试了一下,函数可以正常使用,但是出来的共享目录的名字只有第一个字母,后面的全都没有。遇上汉字的话就会显示乱码,不知道怎么回事,能请教一下吗。多谢。