如何在程序中将一目录设置成共享?
解决方案 »
- 求助。关于dialog下tcp client端发数。
- 关于内核对象的一点疑问
- -----------可能中招了-----------
- 头次使用Timer,在设置Timer时,程序提示"没有找到重载的成员函数"是怎么回事
- 急急急急,关于监听通过gprs由服务器发给客户端的消息
- 请高手解决下怎么样想金山游侠那样动态修改内存
- 用Activemovie 控件时,如何让播放的图象自动按比例适应窗口大小?
- OnPaint()使用问题
- 谁能告诉我怎样在CToolBarCtrl的按钮上添加文本?
- Nobody can help me?
- 为什么ComboBox SetWindowText不能改变显示的内容
- 是否可以给用CPen绘制的线上加提示?
NetShareAddThe NetShareAdd function shares a server resource.
Windows Me/98/95: The parameters for this function are different from those listed in the syntax block. For more information and syntax, see the Windows Me/98/95 information in the Res section.NET_API_STATUS NetShareAdd(
LPWSTR servername,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);Parameters
servername
[in] Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used. This parameter cannot specify the name of a computer that is running Windows 95, Windows 98, or Windows Me. Windows NT: This string must begin with \\.
level
[in] Specifies the information level of the data. This parameter can be one of the following values. Value Meaning
2 Specifies information about the shared resource, including name of the resource, type and permissions, and number of connections. The buf parameter points to a SHARE_INFO_2 structure.
502 Specifies information about the shared resource, including name of the resource, type and permissions, number of connections, and other pertinent information. The buf parameter points to a SHARE_INFO_502 structure. Windows Me/98/95: The following level is valid.Value Meaning
50 Specifies information about the shared resource, including the name and type of the resource, a comment associated with the resource, and passwords. The pbBuffer parameter points to a share_info_50 structure. Note that the string you specify in the shi50_path member must contain only uppercase characters. If the path contains lowercase characters, calls to NetShareAdd can fail with NERR_UnknownDevDir or ERROR_BAD_NET_NAME. buf
[in] Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more information, see Network Management Function Buffers.
parm_err
[out] Pointer to a value that receives the index of the first member of the share information structure that causes the ERROR_INVALID_PARAMETER error. If this parameter is NULL, the index is not returned on error. For more information, see the NetShareSetInfo function.
Return Values
If the function succeeds, the return value is NERR_Success.If the function fails, the return value can be one of the following error codes.Return Code Description
ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_LEVEL The value specified for the level parameter is invalid.
ERROR_INVALID_NAME The character or file system name is invalid.
ERROR_INVALID_PARAMETER The specified parameter is invalid.
NERR_DuplicateShare The share name is already in use on this server.
NERR_RedirectedPath The operation is invalid for a redirected resource. The specified device name is assigned to a shared resource.
NERR_UnknownDevDir The device or directory does not exist. Res
Only members of the Administrators, Server Operators, or Power Users local group, or those with Server Operator group membership, can add file shares with a call to the NetShareAdd function. The Print Operator can add printer shares.If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare.Windows Me/98/95: You must specify the size of the information buffer, in bytes, using the cbBuffer parameter. The parm_err parameter is not available on this platform. Therefore, the parameter list is as follows.extern API_FUNCTION
NetShareAdd(
const char FAR * pszServer,
short sLevel,
const char FAR * pbBuffer,
unsigned short cbBuffer
);
See the NetShareAdd Sample (Windows 95/98/Me) topic to view a code sample that demonstrates how to use the NetShareAdd function.Example Code
The following code sample demonstrates how to share a network resource using a call to the NetShareAdd function. The code sample fills in the members of the SHARE_INFO_2 structure and calls NetShareAdd, 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_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;
}
Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
Header: Declared in Lmshare.h (Svrapi.h on Windows Me/98/95); include Lm.h (Svrapi.h on Windows Me/98/95).
Library: Use Netapi32.lib (use Svrapi.lib on Windows Me/98/95).
See Also
Network Management Overview, Network Management Functions, Share Functions, NetShareDel, NetShareSetInfo, SHARE_INFO_2, SHARE_INFO_502, share_info_50Platform SDK Release: February 2003 What did you think of this topic?
Order a Platform SDK CD Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, and Windows 95.
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server.
Header: Declared in Lmshare.h (Svrapi.h on Windows Me/98/95); include Lm.h (Svrapi.h on Windows Me/98/95).
Library: Use Netapi32.lib (use Svrapi.lib on Windows Me/98/95).See Also
Network Management Overview, Network Management Functions, Share Functions, NetShareDel, NetShareSetInfo, SHARE_INFO_2, SHARE_INFO_502, share_info_50
net share aaa=c:\winnt;