共享网络文件夹

1设置文件夹共享方式为“简单共享文件夹”

 

2编码代码

// test1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#define   UNICODE 
#include   <windows.h> 
#include   <stdio.h> 
#include   <lm.h> 
#pragma comment(lib,"netapi32.lib")

int   wmain(   int   argc,   TCHAR   *argv[   ]) 
{ 
	TCHAR   szShareName[255];
	WCHAR   wszShareName[255];   
	TCHAR   szShareDir[255];   
	WCHAR   wszShareDir[255];
	SHARE_INFO_502   si502;   
	NET_API_STATUS   res;   
	SECURITY_DESCRIPTOR   sd;   
	char*   m_csNetname="ShareDatabase";
	char*   m_csPath="c:\\Download";//制定的共享目录   
	if(!InitializeSecurityDescriptor(&sd,   SECURITY_DESCRIPTOR_REVISION))   
		return 0;
	sprintf(szShareName,   m_csNetname);   
	sprintf(szShareDir,   m_csPath);   

	MultiByteToWideChar(CP_ACP,   0,   szShareName,   -1,   wszShareName,   255);   
	MultiByteToWideChar(CP_ACP,   0,   szShareDir,   -1,   wszShareDir,   255);   

	si502.shi502_netname=wszShareName;   //(char*)wszShareName
	si502.shi502_type=STYPE_DISKTREE;   
	si502.shi502_remark=NULL;   
	si502.shi502_max_uses=100;   
	si502.shi502_permissions=ACCESS_ALL;   
	si502.shi502_current_uses=0;   
	si502.shi502_path=wszShareDir;   //(char*)wszShareDir
	si502.shi502_passwd=NULL;   
	si502.shi502_reserved=0;   
	si502.shi502_security_descriptor=&sd;   
	res=NetShareAdd(   
		NULL,                   //   share   is   on   local   machine   
		502,                         //   info-level   
		(LPBYTE)&si502,   //   info-buffer   
		NULL                         //   don't   bother   with   parm   
		);   
	if(res==NERR_Success)   
		printf("Share   created\n");   
	else   if(res==ERROR_ACCESS_DENIED)   
		printf("The   user   does   not   have   access   to   the requested   information");   
	else   if(res==ERROR_INVALID_LEVEL)   
		printf("The   value   specified   for   the   level   parameter   is   invalid.   ");   
	else   if(res==ERROR_INVALID_NAME)   
		printf("The   character   or   file   system   name   is   invalid.");   
	else   if(res==ERROR_INVALID_PARAMETER)   
		printf("The   specified   parameter   is   invalid.");   
	else   if(NERR_DuplicateShare==res)   
		printf("The   share   name   is   already   in   use   on   this   server.");   
	else   if(NERR_RedirectedPath==res)   
		printf("The   operation   is   invalid   for   a   redirected   resource.   The   specified   device   name   is   assigned   to   a   shared   resource.");   
	else   if(NERR_UnknownDevDir==res)   
		printf("The   device   or   directory   does   not   exist.   ");   
	else
		printf("dfdfd");

	return 0; 
} 


 

http://topic.csdn.net/t/20030820/16/2168863.html

以程序的方式操纵NTFS的文件权限:http://www.lihuasoft.net/article/show.php?id=755

创建一个EveryOne SECURITY_ATTRIBUTES.http://www.cnblogs.com/hbifts/archive/2004/07/12/23550.aspx

 http://www.installsetupconfig.com/win32programming/accesscontrollistaclexample2_1.html

 

http://topic.csdn.net/t/20020611/17/795455.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值