如何共享文件夹,再设置共享文件夹的共享权限?--------------等ing最好有测试的代码。
谢谢!!!
分不够可以在加

解决方案 »

  1.   

    unit   My_Share;   
        
      interface   
      uses   
            SysUtils;   
      type   
          Share_Info50   =   packed   record   
              shi50_netname:   array[0..12]   of   Char;   {13}   
              shi50_type:   Byte;   
              shi50_flags:   Word;   
              shi50_re:   PChar;   
              shi50_path:   PChar;   
              shi50_rw_password:   array[0..8]   of   Char;   {9}   
              shi50_ro_password:   array[0..8]   of   Char;   
          end;   
      const                   
          STYPE_DISKTREE   =   0;   {磁盘共享}   
          STYPE_PRINTQ   =   1;   {打印机共享}   
        
        
          SHI50F_RDONLY   =   1;   {   只读共享}   
          SHI50F_FULL   =   2;   {   完全共享}   
          SHI50F_DEPENDSON   =   (SHI50F_RDONLY   or   SHI50F_FULL);   {进入需要口令}   
        
          SHI50F_PERSIST   =   256;   {此选项:计算机重新启动后才生效}   
          SHI50F_SYSTEM   =   512;   {此选项:即时生效,且击右键无法看到共享}   
      function   ShareResource(ServerName:   PChar;   FilePath:   PChar;   
          NetName:   PChar;   Re:   PChar;   
          ShareType:   Byte;   Flags:   Word;   
          RWPass:   PChar;   ROPass:   PChar):   Integer;   
          function   DeleteShare(ServerName:   PChar;   NetName:   PChar):   Integer;   
      function   NetShareAdd(ServerName:   PChar;   ShareLevel:   SmallInt;   Buffer:   Pointer;   Size:   Word):   Integer;   StdCall;   
      function   NetShareDel(ServerName:   PChar;   NetName:   PChar;   Reserved:   Word):   Integer;   StdCall;   
        
      implementation   
        
      function   ShareResource(ServerName:   PChar;   FilePath:   PChar;   
          NetName:   PChar;   Re:   PChar;   
          ShareType:   Byte;   Flags:   Word;   
          RWPass:   PChar;   ROPass:   PChar):   Integer;   {目录共享}   
      var   
          MyShare:   Share_Info50;   
          PMyShare:   ^Share_Info50;   
      begin   
          strLcopy(MyShare.shi50_netname,   NetName,   13);   
          MyShare.shi50_type   :=   ShareType;   
          MyShare.shi50_flags   :=   Flags;   
          MyShare.shi50_re   :=   Re;   
          MyShare.shi50_path   :=   FilePath;   
          strLcopy(MyShare.shi50_rw_password,   RWPass,   9);   
          strLcopy(MyShare.shi50_ro_password,   ROPass,   9);   
          PMyShare   :=   @MyShare;   
          Result   :=   NetShareAdd(ServerName,   50,   PMyShare,   SizeOf(MyShare));   
      end;   
        
      function   DeleteShare(ServerName:   PChar;   NetName:   PChar):   Integer;   {撤消共享目录}   
      begin   
          Result   :=   NetShareDel(ServerName,   NetName,   0);   
      end;   
        
      function   NetShareAdd;   external   'SVRAPI.DLL';   
      function   NetShareDel;   external   'SVRAPI.DLL';{注意:NT/2000下要改为NETAPI32.DLL,可以在程序中判断系统来加载不同的DLL   }   
      end.   
      

  2.   

    楼上的好像不对哦
    NetShareAdd(ServerName,   50,   PMyShare,   SizeOf(MyShare));   
    这个好像只有2种也
    Value Meaning
    2 The buf parameter points to an array of SHARE_INFO_2 structures.
    502 The buf parameter points to an array of SHARE_INFO_502 structures.
    而且你的只是共享文件夹的代码,还有设置共享访问权限的没有嘛
      

  3.   

    http://community.csdn.net/Expert/topic/5268/5268367.xml?temp=.3922541
    共享访问权限UserInf.SHI_Permissions
      

  4.   

    楼主理解错了,
    level 是指用的类型
    当level是2时 buf用 SHARE_INFO_2 structures.
    当level是502时 buf用 SHARE_INFO_502 structures.而且可以设置权限,SHARE_INFO_502.shi502_permissions就是设置权限的,包括以下权限:
    ACCESS_READ Permission to read data from a resource and, by default, to execute the resource.
    ACCESS_WRITE Permission to write data to the resource.
    ACCESS_CREATE Permission to create an instance of the resource (such as a file); data can be written to the resource as the resource is created.
    ACCESS_EXEC Permission to execute the resource.
    ACCESS_DELETE Permission to delete the resource.
    ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified).
    ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.
    ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions.
      

  5.   

    shi_permissionsValue
    ACCESS_READ
    ACCESS_WRITE
    ACCESS_CREATE
    ACCESS_EXEC
    ACCESS_DELETE
    ACCESS_ATRIB
    ACCESS_PERM
    ACCESS_ALL
     
      

  6.   

    应该有相关的API楼主可以查查
      

  7.   

    注册表路径
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares
      

  8.   

    下载个控件,啥都搞定了。 Sharing v3.0
      

  9.   

    下载位置:http://www.delphi-files.com/download/vcl/filedrv/files/sharing98.zip