1.你用TOpenDialog,也可以选择网上邻居里的共享目录。
2.NetShareAdd()函数的详细应用和参数意义,可以看MSDN.
eg.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
PShare2Info = ^TShare2Info;
TShare2Info = packed Record
ShareName: PWideChar;
ShareType: DWORD;
ShareRemark: PWideChar;
SharePermissions: DWORD;
ShareMaxUser: DWORD;
ShareCurUser: DWORD;
SharePath: PWideChar;
SharePasswd: PWideChar;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Edit2: TEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TSHARE_INFO_502 = record //根据API里那个Struct的要求而用Delphi仿制的
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;
// PBYTE = ^BYTE;
// PWideChar=^WideChar;
function NetShareAdd502(ServerName
WideChar;
level: DWORD;
buf: PBYTE;
VAR parm_err: DWORD ): DWORD; stdcall;
function NetShareAdd(ServerName
WideChar;
Level: DWord;
Buf: PByte;
var Parm_err: DWORD
): DWORD; stdcall;
function NetShareDel(ServerName: PWideChar;
NetName: PWideChar;
Reserved: DWord): DWord; stdcall
var
Form1: TForm1;
implementation
{$R *.DFM}
function NetShareAdd; external 'netapi32.dll' name 'NetShareAdd';
function NetShareAdd502; external 'netapi32.DLL' name 'NetShareAdd';
function NetShareDel; external 'netapi32.DLL' name 'NetShareDel';
// Use NetShareAdd;
procedure TForm1.Button1Click(Sender: TObject);
var
FInfo: TShare2Info;
P, S: Dword;
begin
FInfo.ShareName := 'abc';
FInfo.ShareType := 0;
Finfo.ShareRemark := nil;
FInfo.SharePermissions :=0;
FInfo.ShareMaxUser := $FFFFFFFF;
FInfo.ShareCurUser := 0;
FInfo.SharePath := 'D:/persnal';
FInfo.SharePasswd := 'shdjdm';
S := NetShareAdd('//shd2k', 2, @FInfo, p);
Edit1.Text := IntToStr(S);
if S = 0 then ShowMessage('OKOK')
end;
// Use NetShareAdd502;
procedure TForm1.Button2Click(Sender: TObject);
var
si: TSHARE_INFO_502;
r: DWORD;
parm_err
word;
begin
si.shi502_netname := 'share1'; //共享名
si.shi502_type := 0; //STYPE_DISKTREE
si.shi502_remark := nil;
si.shi502_max_uses := $FFFFFFFF;
si.shi502_current_uses := 10;
si.shi502_path := 'D:/test'; //在机器shd2k上的绝对路径
si.shi502_passwd := nil; //共享目录口令
si.shi502_reserved := 0;
si.shi502_security_descriptor := nil;
// si.shi502_permissions:=TRUSTEE_ACCESS_ALL;
r := NetShareAdd502('//Shd2k', 502, @si, parm_err );
Edit1.Text := Format( '%d', [r] ); //显示结果总是53--未知的机器名
Edit2.Text:=inttostr(parm_err);
end;
// Use NetShareDel;
procedure TForm1.Button3Click(Sender: TObject);
begin
Edit2.Text := IntTOstr(NetShareDel('//shd2k', 'Share1', 0));
end;
end.
3.强制转换位整型数据。