Einzelnen Beitrag anzeigen

TillWe

Registriert seit: 20. Apr 2005
26 Beiträge
 
#1

Ordnerfreigabe: Problem mit Read Only-Freigabe

  Alt 23. Sep 2006, 20:39
Hallo,
ich möchte einen Orner im Netzwerk freigeben. Allerdings soll auf das Verzeichnis vom Netzwerk aus nur lesend zugegriffen werden.
Hierzu habe ich zunächst die Funkition ShareDir verwendet, aus dem Easy Delphi Helper von dsdt.info:
Delphi-Quellcode:
if not ShareDir(ExcludeTrailingPathDelimiter(label3.caption), 'koffein', '', True) then
//...
Das Problem:
Der Ordner wird zwar freigegeben aber immer mit Schreizugriff, also nicht readonly!
Weiß jemand Abhilfe bzw. woran das liegen könnte?

mfg

Hier noch mal zur besseren Info die Funktion aus dem Easy Helper (so wie ich sie eingebunden habe):
Delphi-Quellcode:
unit types_functions_u;
uses
 //[...]
interface
const
SType_DiskTree = 0;
Access_Read = 1;
Access_All = 127;
Nerr_Success = 0;

type
TShareInfo2ExW = record
 shi2_NetName: PWideChar;
 shi2_Type: Longword;
 shi2_Remark: PWideChar;
 shi2_Permissions: Longword;
 shi2_Max_Uses: Longword;
 shi2_Current_Uses: Longword;
 shi2_Path: PWideChar;
 shi2_Passwd: PWideChar;
end;

TShareInfo2ExA= record
 shi2_NetName: PAnsiChar;
 shi2_Type: Longword;
 shi2_Remark: PAnsiChar;
 shi2_Permissions: Longword;
 shi2_Max_Uses: Longword;
 shi2_Current_Uses: Longword;
 shi2_Path: PAnsiChar;
 shi2_Passwd: PAnsiChar;
end;

type
TNetShareAddFunc = function (servername: PChar; level: Longword;
                             const buf: Pointer;
                             parm_err: PLongWord): LongWord; stdcall;
 //[...]
function ShareDir(const ADir, AName, APassword: WideString; ReadOnly: Boolean): Boolean;
 //[...]

implementation


function ShareDirA(const ADir, AName, APassword: string; ReadOnly: Boolean): Boolean;
var
Info: TShareInfo2ExA;
Err: Longword;

Lib: THandle;
NetShareAddFunc: TNetShareAddFunc;
begin
Result:=False;
Lib:= LoadLibrary('Svrapi.dll');

if Lib <> 0 then
begin
  try
    @NetShareAddFunc:= GetProcAddress(Lib,'NetShareAdd');
    if @NetShareAddFunc <> nil then
    begin
       FillChar(Info, SizeOf(Info), 0);
       Info.shi2_netname := PAnsiChar(AName);
       Info.shi2_type := SType_DiskTree;
       Info.shi2_remark := nil;
       if ReadOnly then
         Info.shi2_permissions := Access_Read
       else
         Info.shi2_permissions := Access_All;
       Info.shi2_max_uses := LongWord(-1);
       Info.shi2_current_uses := 0;
       Info.shi2_path := PAnsiChar(ADir);
       Info.shi2_passwd := PAnsiChar(APassword);
       Result := NetShareAddFunc(nil, 2, @Info, @Err) = NERR_SUCCESS;
    end
    else
      RaiseLastOSError;
  finally
    FreeLibrary(Lib);
  end;
end;
end;

function ShareDirW(const ADir, AName, APassword: WideString; ReadOnly: Boolean): Boolean;
var
Info: TShareInfo2ExW;
Err: Longword;

Lib: THandle;
NetShareAddFunc: TNetShareAddFunc;
begin
Result:=False;
Lib:= LoadLibrary('Netapi32.dll');

if Lib <> 0 then
begin
  try
    @NetShareAddFunc:= GetProcAddress(Lib,'NetShareAdd');
    if @NetShareAddFunc <> nil then
    begin
     FillChar(Info, SizeOf(Info), 0);
     Info.shi2_netname := PWideChar(AName);
     Info.shi2_type := SType_DiskTree;
     Info.shi2_remark := nil;
     if ReadOnly then
       Info.shi2_permissions := Access_Read
     else
       Info.shi2_permissions := Access_All;
     Info.shi2_max_uses := LongWord(-1);
     Info.shi2_current_uses := 0;
     Info.shi2_path := PWideChar(ADir);
     Info.shi2_passwd := PWideChar(APassword);
     Result := NetShareAddFunc(nil, 2, @Info, @Err) = Nerr_Success;
    end
    else
      RaiseLastOSError;
  finally
    FreeLibrary(Lib);
  end;
end;
end;

function ShareDir(const ADir, AName, APassword: WideString; ReadOnly: Boolean): Boolean;
begin
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
  Result := ShareDirA(ADir, AName, APassword, ReadOnly)
else
  Result := ShareDirW(ADir, AName, APassword, ReadOnly);
end;
 //[...]
  Mit Zitat antworten Zitat