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