AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi Netzwerkfreigabe - Problem mit Zugriffsrechten...
Thema durchsuchen
Ansicht
Themen-Optionen

Netzwerkfreigabe - Problem mit Zugriffsrechten...

Ein Thema von Adversus · begonnen am 28. Apr 2006 · letzter Beitrag vom 3. Mai 2006
Antwort Antwort
Adversus

Registriert seit: 12. Jan 2006
12 Beiträge
 
#1

Netzwerkfreigabe - Problem mit Zugriffsrechten...

  Alt 28. Apr 2006, 11:07
Hi All !

Also ich benutze in meinem Programm folgende Funktion um Verzeichnisse um Ordner freizugeben...

Delphi-Quellcode:
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 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;
Den Code hab ich von der dsdt.info. Das Problem ist nun das ich bei
ShareDir('C:\freigabe', 'Freigabe-Ordner', '', True) laut Windowsfreigabe
diesen Ordner trotzdem als veränderbar freigegeben hab...
Frage: Wo ist der Fehler ???

thx, Adversus
  Mit Zitat antworten Zitat
Christian Seehase
(Co-Admin)

Registriert seit: 29. Mai 2002
Ort: Hamburg
11.105 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Netzwerkfreigabe - Problem mit Zugriffsrechten...

  Alt 30. Apr 2006, 02:41
Moin Adversus,

die Doku sagt dazu folgendes:

Zitat von PSDK - SHARE_INFO_2 :
shi2_permissions
Specifies a DWORD value that indicates the shared resource's permissions for servers running with share-level security. A server running user-level security ignores this member. This member can be one or more of the following values. Calls to the NetShareSetInfo function ignore this member.
Note that the Windows Server 2003 family, Windows XP, Windows 2000, and Windows NT do not support share-level security.
Tschüss Chris
Die drei Feinde des Programmierers: Sonne, Frischluft und dieses unerträgliche Gebrüll der Vögel.
Der Klügere gibt solange nach bis er der Dumme ist
  Mit Zitat antworten Zitat
Adversus

Registriert seit: 12. Jan 2006
12 Beiträge
 
#3

Re: Netzwerkfreigabe - Problem mit Zugriffsrechten...

  Alt 3. Mai 2006, 08:31
...also wenn ich dich richtig verstehe gibts gar keine möglichkeit das auf diese weise zu machen ?! Hat vielleicht jemand ne idee wie man das anders machen könnte ????
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz