unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function checksharedpermission(sharedpath:string; Out netstat:ShortString):boolean;
var
MS:TMemoryStream;
st:char;
netpermis:boolean;
begin
MS := TMemoryStream.Create;
st:='x';
ms.Write(st,1);
MS.Seek(0,soFromBeginning);
try
netpermis:=true;
ms.SaveToFile(sharedpath + '\x');
except
on E : Exception do
begin
if pos('denied',e.Message)>0 then netstat:='denied';
if pos('not found',e.Message)>0 then netstat:='not found';
netpermis:=false;
end;
end;
ms.Free;
if netpermis=true then
deletefile(sharedpath + '\x');
result := netpermis;
end;
procedure TForm1.Button1Click(Sender: TObject);
var netstat:ShortString;
begin
if checksharedpermission('\\iserver\gfiles',netstat)=true then
begin
showmessage('Shared Folder/Drive is Found and Writable');
end
else
begin
showmessage('Shared Folder/Drive is '+ netstat);
end;
end;
end.
|