这我的这一段代码为什么总不能创建一个共享呢?我是用Delphi6
unit U_Share;
interface
uses
Windows,Sysutils,Dialogs ;
type
//纪录类型声明,注意参数类型的正确对应,最好别看 delphi 的帮助,引起误导
TSHARE_INFO_502 = record
shi502_netname: PWideChar;
shi502_type: DWORD;
shi502_remark: PWideChar;
shi502_permissions: DWORD;
shi502_max_uses: DWORD;
shi502_current_uses: DWORD;
shi502_path: PWideChar;
shi502_passwd: PWideChar;
shi502_reserved: DWORD;
shi502_security_descriptor: PSECURITY_DESCRIPTOR;
end;
//添加共享
function NetShareAdd(servername:Widestring; level: DWORD; Buf: PBYTE;
var parm_err: PDWORD ): DWORD; stdcall;
//删除共享
function NetShareDel(ServerName:Widestring; NetName: Widestring;
Reserved: DWord): Integer; StdCall; //}
const
{共享类型}
STYPE_DISKTREE = 0 ;
STYPE_PRINTQ = 1 ;
STYPE_DEVICE = 2 ;
STYPE_IPC = 3 ;
{访问权限}
ACCESS_READ = 0 ;
ACCESS_WRITE = 1 ;
ACCESS_CREATE = 2 ;
ACCESS_EXEC = 3 ;
ACCESS_DELETE = 4 ;
ACCESS_ALL = 7 ;
//自己声明的函数,为了调用方便,参数就不用说明了吧!
function ShareResource(ServerName,FilePath,NetName, Remark : string): Integer;
//function DeleteShare(ServerName: string; NetName: string): Integer;
implementation
//注意在 windows95/98/me 下面 dll 库是 SVRAPI.DLL ,而且参数类型也要随之改变的吆!
function NetShareAdd; external 'netapi32.DLL' name 'NetShareAdd';
function NetShareDel; external 'netapi32.DLL' name 'NetShareDel';
function ShareResource(ServerName,FilePath,NetName, Remark : string): Integer;
var
ShInfo: TSHARE_INFO_502;
parm_err
DWORD;
_FilePath,_NetName, _Remark : PWideChar ;
_ServerName : Pchar ;
begin
_ServerName := PChar(ServerName);
_FilePath := PWideChar(FilePath);
_NetName := PWideChar(NetName);
_Remark := PWideChar(Remark);
Shinfo.shi502_netname := _NetName;
Shinfo.shi502_type := STYPE_DISKTREE;
shinfo.shi502_remark := _Remark;
Shinfo.shi502_permissions := ACCESS_ALL;
Shinfo.shi502_max_uses := $FFFFFFFF;
Shinfo.shi502_current_uses := 10;
Shinfo.shi502_path := _FilePath;
Shinfo.shi502_passwd := Nil;
Shinfo.shi502_reserved := 0;
Shinfo.shi502_security_descriptor := Nil;
Result := NetShareAdd(_ServerName, 502, @ShInfo, parm_err);
end;
end.