Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 06.10.05 08:55 
Wie kann man mit einem Delphi-Programm unter WIN XP Netzwerkfreigaben, also Ordner die in der netzwerkumgebung zu sehen sind, wieder sperren, d. h. dass sie nicht mehr zu sehen sind. Hab über die Forensuche nix passendes gefunden.

Greetz koller

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Do 06.10.05 09:17 

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
koller1
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 216

WIN XP
D7 Ent
BeitragVerfasst: Do 06.10.05 20:43 
Bei dem Artikel gehts ja um Netzlaufwerke, aber wir meinen Ordnerfreigaben im Netzwerk. Das ist was anderes ;-)

So, hier mal unser Code für das freigeben eines ordners. Da das rückgängig machen dieser Funktion ja nur eine Umkehrfunktion dieser Funktion ist, müssen ja nur ein paar Sachen verändert werden, oder?

Hier mal der Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
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(nil2, @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(nil2, @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;


Was müsste man dort verändern?

MFG
koller1

_________________
PLEASE INSERT SYSTEM DISK AND PRESS ENTER!
Und wenn du nicht gestorben bist, presst du noch heute! ;)
blaueled
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 133

Win XP
D5
BeitragVerfasst: Do 06.10.05 20:55 
Hallo,

mit
ausblenden Quelltext
1:
net share {Freigabename | Gerätename | Laufwerk:Pfad} /DELETE					

Kann man bequem Freigaben löschen und anlegen.

Arne
koller1
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 216

WIN XP
D7 Ent
BeitragVerfasst: Fr 07.10.05 21:58 
Und das kann man einfach so in Delphi einbauen? Also wie ich das sehe ist das auf Kommandozeilenebene und dazu brauch man eine *.bat Datei. Aber dann ist ja wieder sichtbar, was der PC macht, indem der dann ja die cmd.exe öffnet. Also nochmal um auf den Code zurück zu kommen, den ich benutze. Er funzt super und es klappt alles "unbemerkt" ;-)! Bloß wie ändere ich den Code so um, dass er diesen freigegebenen Ordner wieder zu einem "normalen" Ordner macht. PS. Das Prog soll nicht von einem PC auf dem anderen zugreifen, sonder auf dem PC, wo es läuft Ordner freigeben...

MFG
koller1

_________________
PLEASE INSERT SYSTEM DISK AND PRESS ENTER!
Und wenn du nicht gestorben bist, presst du noch heute! ;)