在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
Char;
path
Char;
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
Dword) : 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
Word;
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.