// ¾Æ·¡ ¿¹Á¦´Â Windows NT/Windows 2000 ´Â Áö¿øÇÏÁö ¾Ê½À´Ï´Ù
// ´Ù¸¥ Ç÷§ÆûÀº MSDN »çÀÌÆ®¸¦ Âü°íÇϼ¼¿ä
// http://msdn.microsoft.com/library/sdkdoc/network/ntlmapi_18bz.htm
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
// Win95/98 ¿¡¼ share info´Â 0,1,2,50 structure ¸¸ »ç¿ë°¡´É
// Windows NT¿¡¼ share info´Â 0,1,2,501,502,1005 structure ¸¸ »ç¿ë°¡´É
Share_Info50 = packed record
shi50_netname : array[0..12] of Char; {13}
shi50_type : Byte;
shi50_flags : Word;
shi50_remark : PChar;
shi50_path : PChar;
shi50_rw_password : array[0..8] of Char; {9}
shi50_ro_password : array[0..8] of Char;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function NetShareAdd(ServerName: PChar;
ShareLevel: SmallInt;
Buffer: Pointer;
Size: Word): Integer; stdcall; external 'SVRAPI.DLL';
function NetShareDel(ServerName: PChar;
NetName: PChar;
Reserved: Word): Integer; stdcall; external 'SVRAPI.DLL';
function ShareResource(ServerName: PChar; FilePath: PChar;
NetName: PChar; Remark: PChar;
ShareType: Byte; Flags: Word;
RWPass: PChar; ROPass: PChar): Integer;
var
MyShare: Share_Info50;
PMyShare: ^Share_Info50;
begin
strLcopy(MyShare.shi50_netname, NetName, 13);
MyShare.shi50_type := ShareType;
MyShare.shi50_flags := Flags;
MyShare.shi50_remark := Remark;
MyShare.shi50_path := FilePath;
strLcopy(MyShare.shi50_rw_password, RWPass, 9);
strLcopy(MyShare.shi50_ro_password, ROPass, 9);
PMyShare := @MyShare;
Result := NetShareAdd(ServerName, 50, PMyShare, SizeOf(MyShare));
end;
function DeleteShare(ServerName: PChar; NetName: PChar): Integer;
begin
Result := NetShareDel(ServerName,NetName, 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
rt: Integer;
begin
rt := ShareResource(nil, // ÄÄÇ»ÅÍ À̸§ (nil Àº Local MachineÀ» ÀǹÌÇÕ´Ï´Ù)
'C:ZZZ', // °øÀ¯ÇÒ Æú´õ (ÀüºÎ ´ë¹®ÀÚ·Î ÁöÁ¤)
'ZZZ', // °øÀ¯À̸§
'°øÀ¯¿¹Á¦', // ¼³¸í
0, // 0=µð·ºÅ丮 °øÀ¯, 1=ÇÁ¸°ÅÍ °øÀ¯
// 256 or 1= Àбâ Àü¿ë, 256 or 2=Àбâ/¾²±â, 256 or 1 or 2=¾ÏÈ£¿¡ µû¶ó ´Ù¸§
256 or 1 or 2,
'1111', // Àбâ/¾²±â ¾ÏÈ£
'2222'); // Àбâ Àü¿ë ¾ÏÈ£
if rt = 0 then
ShowMessage('Æú´õ°¡ °øÀ¯µÇ¾ú½À´Ï´Ù')
else
ShowMessage('Æú´õ¸¦ °øÀ¯ÇÒ ¼ö ¾ø½À´Ï´Ù. ¿¡·¯¹øÈ£('+IntToStr(rt)+')');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
rt: Integer;
begin
rt := DeleteShare(nil, 'ZZZ');
if rt = 0 then
ShowMessage('Æú´õÀÇ °øÀ¯¸¦ ÇØÁ¦ÇÏ¿´½À´Ï´Ù')
else
ShowMessage('Æú´õÀÇ °øÀ¯¸¦ ÇØÁ¦ÇÒ ¼ö ¾ø½À´Ï´Ù. ¿¡·¯¹øÈ£('+IntToStr(rt)+')');
end;
end. |
|