怎样创建一个共享文件夹?

解决方案 »

  1.   

    http://www.yesky.com/20030325/1658998.shtml
      

  2.   

    参考VB代码:
      当然最好还是用API函数来设置共享了,ServerName改一下就行了。  
     
    Option  Explicit  
    Private  Declare  Function  NetShareAdd  Lib  "netapi32"  (ByVal  ServerName  As  Long,  ByVal  level  As  Long,  buf  As  Any,  parmerr  As  Long)  As  Long  
    Private  Type  SHARE_INFO_2  
           shi2_netname              As  Long                '共享名  
           shi2_type                    As  Long                '类型  
           shi2_re                As  Long                '备注  
           shi2_permissions      As  Long                '权限  
           shi2_max_uses            As  Long                '最大用户  
           shi2_current_uses    As  Long                '  
           shi2_path                    As  Long                '路径  
           shi2_passwd                As  Long                '密码  
    End  Type  
     
    Const  STYPE_ALL  =  -1  
    Const  STYPE_DISKTREE  =  0  
    Const  STYPE_PRINTQ  =  1  
    Const  STYPE_DEVICE  =  2  
    Const  STYPE_IPC  =  3  
    Const  STYPE_SPECIAL  =  &H80000000  
     
    Const  ACCESS_READ  =  &H1  
    Const  ACCESS_WRITE  =  &H2  
    Const  ACCESS_CREATE  =  &H4  
    Const  ACCESS_EXEC  =  &H8  
    Const  ACCESS_DELETE  =  &H10  
    Const  ACCESS_ATRIB  =  &H20  
    Const  ACCESS_PERM  =  &H40  
    Const  ACCESS_ALL  =  ACCESS_READ  Or  ACCESS_WRITE  Or  ACCESS_CREATE  Or  ACCESS_EXEC  Or  ACCESS_DELETE  Or  ACCESS_ATRIB  Or  ACCESS_PERM  
     
    '  为指定的计算机添加共享  
    '  Server  为计算机名,  SharePath  为共享路径,  ShareName  为共享名,  ShareRe  为备注,  SharePw  为密码  
    Function  AddShare(Server  As  String,  SharePath  As  String,  ShareName  As  String,  ShareRe  As  String,  SharePw  As  String)  As  Boolean  
           Dim  lngServer      As  Long  
           Dim  lngNetname    As  Long  
           Dim  lngPath          As  Long  
           Dim  lngRe      As  Long  
           Dim  lngPw              As  Long  
           Dim  parmerr        As  Long  
           Dim  si2                As  SHARE_INFO_2  
             
           lngServer  =  StrPtr(Server)  
           lngNetname  =  StrPtr(ShareName)  
           lngPath  =  StrPtr(SharePath)  
             
           If  Len(ShareRe)  >  0  Then  
                   lngRe  =  StrPtr(ShareRe)  
           End  If  
             
           If  Len(SharePw)  >  0  Then  
                   lngPw  =  StrPtr(SharePw)  
           End  If  
                   
           With  si2  
                   .shi2_netname  =  lngNetname  
                   .shi2_path  =  lngPath  
                   .shi2_re  =  lngRe  
                   .shi2_type  =  STYPE_DISKTREE  
                   .shi2_permissions  =  ACCESS_ALL  
                   .shi2_max_uses  =  -1  
                   .shi2_passwd  =  lngPw  
           End  With  
             
           If  NetShareAdd(lngServer,  2,  si2,  parmerr)  =  0  Then  
                   AddShare  =  True  
           Else  
                   AddShare  =  False  
           End  If  
    End  Function  
     
    Private  Sub  Command1_Click()  
           MkDir  "c:\123"  
           AddShare  "server",  "c:\123",  "C盘的一个文件夹",  "这只是一个例子",  ""  
    End  Sub  
     
     
      

  3.   

    NET_API_STATUS NetShareAdd(
      LPWSTR servername,
      DWORD level,
      LPBYTE buf,
      LPDWORD parm_err
    );NET_API_STATUS NetShareDel(
      LPWSTR servername,
      LPWSTR netname,
      DWORD reserved
    );
      

  4.   

    添加一个共享#define UNICODE
    #include <windows.h>
    #include <stdio.h>
    #include <lm.h>void wmain( int argc, TCHAR *argv[ ])
    {
       NET_API_STATUS res;
       SHARE_INFO_2 p;
       DWORD parm_err = 0;   if(argc<2)
          printf("Usage: NetShareAdd server\n");
       else
       {
          //
          // Fill in the SHARE_INFO_2 structure.
          //
          p.shi2_netname = TEXT("TESTSHARE");    
          p.shi2_type = STYPE_DISKTREE; // disk drive
          p.shi2_re = TEXT("TESTSHARE to test NetShareAdd");
          p.shi2_permissions = 0;    
          p.shi2_max_uses = 4;
          p.shi2_current_uses = 0;    
          p.shi2_path = TEXT("C:\\");
          p.shi2_passwd = NULL; // no password
          //
          // Call the NetShareAdd function,
          //  specifying level 2.
          //
          res=NetShareAdd(argv[1], 2, (LPBYTE) &p, &parm_err);
          //
          // If the call succeeds, inform the user.
          //
          if(res==0)
             printf("Share created.\n");
          
          // Otherwise, print an error,
          //  and identify the parameter in error.
          //
          else
             printf("Error: %u\tparmerr=%u\n", res, parm_err);
       }
       return;
    }删除一个共享#define UNICODE
    #include <windows.h>
    #include <stdio.h>
    #include <lm.h>void wmain( int argc, TCHAR *argv[ ])
    {
       NET_API_STATUS res;   if(argc<3)
          printf("Usage: NetShareDel server share\n");
       else
       {
          //
          // Call the NetShareDel function to delete the share.
          //
          res=NetShareDel(argv[1], argv[2], 0);
          //
          // Display the result of the call.
          //
          if(res==0)
             printf("Share Removed.\n");
          else
             printf("Error: %u\n", res);
       }
       return;
    }
      

  5.   

    dos 命令:
    net share ....
    net share delete....
    可以参照dos帮助啊