还是不太会使用netshareadd函数!(100分)

  • 主题发起人 主题发起人 lonelybug
  • 开始时间 开始时间
L

lonelybug

Unregistered / Unconfirmed
GUEST, unregistred user!
主要问题是,目录道是可以成为共享文件夹了!可是不能设置密码,和权限,可是确实可以有这两方面的函数呀,而且有没有人可以吧这些函数的中文使用方法告诉我!
不好意思,还有一个傻问题,就是getwindowsDirectory这个函数怎么用呢!我不太明白里面的最后一个函数应该如何写!?
比如GetWindowsDirectory(
LPTSTR lpBuffer, // buffer for Windows directory
UINT uSize )
这里面的第二个参数如何谢,第一个试pchar的返回的windows安装的目录位置把!?
谢谢了!
 
NET_API_STATUS NetShareAdd(
LPTSTR servername,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);

Parameters
servername
Pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.
level
Specifies one of the following values to set the level of information provided.
Value Meaning
2 The buf parameter points to an array of SHARE_INFO_2 structures.
502 The buf parameter points to an array of SHARE_INFO_502 structures.

buf
Pointer to the buffer in which the data set with the level parameter is stored.
parm_err
Optional pointer to a DWORD that contains the index of the first parameter that causes ERROR_INVALID_PARAMETER. If NULL, the parameter is not returned on error.
The SHARE_INFO_2 structure contains information about the shared resource, including name of the resource, type and permissions, and number of connections.
typedef struct _SHARE_INFO_2 {
LPTSTR shi2_netname;
DWORD shi2_type;
LPTSTR shi2_remark;
DWORD shi2_permissions;
DWORD shi2_max_uses;
DWORD shi2_current_uses;
LPTSTR shi2_path;
LPTSTR shi2_passwd;
} SHARE_INFO_2, *PSHARE_INFO_2, *LPSHARE_INFO_2;

Members
shi2_netname
A Unicode string containing the sharename of a resource.
shi2_type
This member can be one of the following types:
Value Meaning
STYPE_DISKTREE Disk drive
STYPE_PRINTQ Print queue
STYPE_DEVICE Communication device
STYPE_IPC Interprocess Communication (IPC)

shi2_remark
Points to a Unicode string that contains an optional comment about the shared resource.
shi2_permissions
Specifies the shared resource's permissions for servers running with share-level security. A server running user-level security ignores this member.This member can be one or more of the following values.
Value Meaning
ACCESS_READ Permission to read data from a resource and, by default, to execute the resource.
ACCESS_WRITE Permission to write data to the resource.
ACCESS_CREATE Permission to create an instance of the resource (such as a file);
data can be written to the resource as the resource is created.
ACCESS_EXEC Permission to execute the resource.
ACCESS_DELETE Permission to delete the resource.
ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified).
ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.
ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions.

shi2_max_uses
Indicates the maximum number of concurrent connections that the shared resource can accommodate (unlimited if the value specified in shi2_max_uses is -1).
shi2_current_uses
Specifies the number of current connections to the resource.
shi2_path
Points to a Unicode string containing the local path for the shared resource. For disks, shi2_path is the path being shared. For print queues, shi2_path is the name of the print queue being shared.
shi2_passwd ///////////////////////口令
Specifies the share's password (when the server is running with share-level security). If the server is running with user-level security, shi2_passwd is ignored. The shi2_passwd member can be no longer than SHPWLEN+1 bytes (including a terminating null character).
The SHARE_INFO_502 structure contains information about the shared resource, including name of the resource, type and permissions, and number of connections.
typedef struct _SHARE_INFO_502 {
LPTSTR shi502_netname;
DWORD shi502_type;
LPTSTR shi502_remark;
DWORD shi502_permissions;
DWORD shi502_max_uses;
DWORD shi502_current_uses;
LPTSTR shi502_path;
LPTSTR shi502_passwd;
DWORD shi502_reserved;
PSECURITY_DESCRIPTOR shi502_security_descriptor;
} SHARE_INFO_502, *PSHARE_INFO_502, *LPSHARE_INFO_502;

Members
shi502_netname
A Unicode string containing the sharename of a resource.
shi502_type
One of the following four values specifying the type of share:
Value Meaning
STYPE_DISKTREE Disk Drive
STYPE_PRINTQ Print Queue
STYPE_DEVICE Communication device
STYPE_IPC Interprocess Communication (IPC)

shi502_remark
Points to a Unicode string containing an optional comment about the shared resource.
shi502_permissions
Specifies the shared resource's permissions for servers running with share-level security.This member is ignored on a server running user-level security. This member can be any of the following values:
Value Meaning
ACCESS_READ Permission to read data from a resource and, by default, to execute the resource.
ACCESS_WRITE Permission to write data to the resource.
ACCESS_CREATE Permission to create an instance of the resource (such as a file);
data can be written to the resource as the resource is created.
ACCESS_EXEC Permission to execute the resource.
ACCESS_DELETE Permission to delete the resource.
ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified).
ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.
ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions.

shi502_max_uses
Indicates the maximum number of concurrent connections that the shared resource can accommodate (unlimited if the value specified in shi502_max_uses is -1).
shi502_current_uses
Specifies the number of current connections to the resource.
shi502_path
Points to a Unicode string that contains the local path for the shared resource. For disks, shi502_path is the path being shared. For print queues, shi502_path is the name of the print queue being shared.
shi502_passwd //////////////口令
Specifies the share's password (when the server is running with share-level security). If the server is running with user-level security, shi502_passwd is ignored. The shi502_passwd member can be no longer than SHPWLEN+1 bytes (including a terminating null character).
shi502_reserved
Must be zero.
shi502_security_descriptor
Specifies the Windows NT security descriptor associated with this share.

getwindowsDirectory的用法:
procedure TForm1.Button1Click(Sender: TObject);
var
d:array [0..max_path] of char;
begin
getwindowsDirectory(d,max_path-1);
showmessage(d);
end;
 
谢谢呀!不过这种说明文件根本没有例子,所以才来问的,你贴了等于还是没有帮我1
 
help帮帮我,我真得很需要!
 
这不是写的很清楚了吗?
你还要怎么样啊?
如果你认为帮助都没有用的话,那么你是不是认为微软花这么大力气写的msdn
是他们做的最愚蠢的意见事呢?
 
那你会用吗!?不见得吧!要是都用msdn就知道一个函数如何用的话那出书干什么!都复印不就完了!我不想跟你正这个,我只想要一个例子的元代吗!有就给,没有别再这浪费叶面了!smilesnake你会不会的是你的事,请你别给别人添乱了!!
 
TShare_INFO_2 = record
shi2_netname : PWideChar;
shi2_type : Longword;
shi2_remark : PWideChar;
shi2_permissions : Longword;
shi2_max_uses : Longword;
shi2_current_uses : Longword;
shi2_path : PWideChar;
shi2_passwd : PWideChar;
end;
function NetShareAdd(ServerName : PWideChar;
Level : Longword;
Buffer : Pointer;
var ParamError : Longword) : Longword;
var
Form1: TForm1;
implementation
function NetShareAdd;
external 'netapi32.DLL' name 'NetShareAdd';
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
shareAttrresult,shareAttrtemp:string;
i:integer;
si: TSHARE_INFO_2;
parm_err:Longword;
severname: pchar;
servername:OSVERSIONINFO;
PwString:PwideChar;
wstring:string;
begin
wstring:='savedfdf';
si.shi2_netname :='save';//这里如果用一个string的型的变量然后用pwidechar()来把他转化成pwidechar类型的话最后里乱吗
si.shi2_type :=0;
si.shi2_remark :='abcde';//这里也和上面的一样
si.shi2_permissions := ;//这里如果填写ACCESS_READ这类的参数的话程序说未指定ACCESS_READ(其他的参数也一样)
si.shi2_max_uses :=10;
si.shi2_current_uses :=10;
si.shi2_path :='f:/save';
si.shi2_passwd :='123456';//这个密码设定之后和没有设定好像没有什么变化,如何使这个密码有效果,或者如何可以看出密码成功设定了!谢谢了!
//GetVersionEx(servername);
NetShareAdd('lonelybug',2,@si,parm_err);
‘lonelybug’是计算机的名字请问我想面的这个程序写的队吗!?
 
可能该函数一开始在Win98中有bug,不能按老的MSDN文档或Delphi在线文档
中的说明做。微软的最新文档用的是 SHARE_INFO_50 结构,在 win2000中
仍用 SHARE_INFO_2。以下是微软的 C声明和示例:
98x
typedef struct _share_info_50
{
char shi50_netname[LM20_NNLEN+1];
unsigned char shi50_type;
unsigned short shi50_flags;
char FAR* shi50_remark;
char FAR* shi50_path;
char shi50_rw_password[SHPWLEN+1];
char shi50_ro_password[SHPWLEN+1];
} _share_info_50;

#include <stdio.h>
#include <windows.h>
#include <svrapi.h>
int main(int argc, char FAR * argv[])
{
char FAR * pszServerName = NULL;
short nLevel = 50;
struct share_info_50* pBuf = NULL;
unsigned short cbBuffer;
NET_API_STATUS nStatus;
//
// ServerName can be NULL to indicate the local computer.
//
if ((argc < 3) || (argc > 4))
{
printf("Usage: %s [////ServerName] ShareName SharePath/n", argv[0]);
exit(1);
}
if (argc == 4)
pszServerName = argv[1];
//
// Allocate the memory required to specify a
// share_info_50 structure.
//
cbBuffer = sizeof(struct share_info_50);
pBuf = malloc(cbBuffer);
if (pBuf == NULL)
printf("No memory/n");
//
// Assign values to the share_info_50 structure.
//
strcpy(pBuf->shi50_netname, argv[argc-2]);
pBuf->shi50_type = STYPE_DISKTREE;
pBuf->shi50_flags = SHI50F_FULL;
pBuf->shi50_remark = NULL;
pBuf->shi50_path = argv[argc-1];
pBuf->shi50_rw_password[0] = '/0';
// No password
pBuf->shi50_ro_password[0] = '/0';
// No password
//
// Call the NetShareAdd function
// specifying information level 50.
//
nStatus = NetShareAdd(pszServerName,
nLevel,
(char FAR *)pBuf,
cbBuffer);
//
// Display the result of the function call.
//
if (nStatus == NERR_Success)
printf("Share added successfully/n");
else
fprintf(stderr, "A system error has occurred: %d/n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
free(pBuf);
return 0;
}
2K
#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;
}
在98平台,试试以下的Delphi实现:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

const NETNAME_LEN = 13;
PASSWORD_LEN = 9;
SHI50F_RDONLY = $0001;
SHI50F_FULL = $0002;
SHI50F_DEPENDSON = $0003;
SHI50F_ACCESSMASK = $0003;
SHI50F_PERSIST = $0100;
SHI50F_SYSTEM = $0200;
STYPE_DISKTREE = 0;
STYPE_PRINTQ = 1;
STYPE_DEVICE = 2;
STYPE_IPC = 3;
NERR_Success = 0;
NERR_BASE = 2100;
//常量说明
NERR_UnKnownDevDir=(NERR_BASE+16);
NERR_UnknownServer=(NERR_BASE+3);
NERR_ServerNotStarted=(NERR_BASE+14);
NERR_RedirectedPath=(NERR_BASE+17);
NERR_DuplicateShare=(NERR_BASE+18);
NERR_BufTooSmalll=(NERR_BASE+23);
type
TSHARE_INFO_50=Record
netname:array [0..NETNAME_LEN-1] of Char;
sharetype:ShortInt;
flags:SmallInt;
remark:PChar;
path:PChar;
rw_password:array [0..PASSWORD_LEN-1] of Char;
ro_password:array [0..PASSWORD_LEN-1] of Char;
end;
//以上为类型定义
function NetShareAdd(ServerName : PWideString;Level : Dword;
Buffer : pByte;ParamError :pDword) : SmallInt;
var
Form1: TForm1;
implementation
{$R *.DFM}
function NetShareAdd;
external 'svrapi.DLL' name 'NetShareAdd';
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
si:TSHARE_INFO_50;
parm_err :DWord;
begin
si.netname:='save';
si.shareType :=STYPE_DISKTREE;
si.flags := SHI50F_FULL;
si.remark :='Abcde';
si.path :='D:/temp';
si.rw_password :='';
si.ro_password :='';
i:=NetShareAdd(nil,50,pbyte(@si),@parm_err);
if (i<>NERR_Success) then
showmessage('Error:'+inttostr(i));
end;
end.
 
接受答案了.
 
后退
顶部