关于添加共享资源的方法

来源:互联网 发布:白色车牌js是什么意思 编辑:程序博客网 时间:2024/06/07 15:38

转载自msdn:ms-help://MS.MSDNQTR.v90.chs/netshare/fs/netshareadd.htm

The following code sample demonstrates how to share a network resource using a call to theNetShareAdd function. The code sample fills in the members of theSHARE_INFO_2 structure and callsNetShareAdd, specifying information level 2. A password is not required because these platforms do not support share-level security.

#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_remark = 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;}

0 0
原创粉丝点击