1:怎么取本机的所有共享名
2:怎么取本机的所有共享名所对应共享路径
3:怎么取本机的所有共享名所对应共享权限分不够可以在加,谢谢各位大侠咯!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        lbxShares: TListBox;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    type
     TShareInfo50 = packed record
      shi50_netname  : array [0..12] of Char;
      shi50_type  : Byte;
      shi50_flags  : Word;
      shi50_re  : PChar;
      shi50_path  : PChar;
      shi50_rw_password  : array [0..8] of Char;
      shi50_ro_password  : array [0..8] of Char;
     end;type
     TShareInfo2 = packed record
      shi2_netname  : PWChar;
      shi2_type : DWORD;
      shi2_re  : PWChar;
      shi2_permissions : DWORD;
      shi2_max_uses  : DWORD;
      shi2_current_uses  : DWORD;
      shi2_path  : PWChar;
      shi2_passwd  : PWChar;
     end;
     PShareInfo2 = ^TShareInfo2;
     TShareInfo2Array = array [0..512] of TShareInfo2;
     PShareInfo2Array = ^TShareInfo2Array;var
      Form1: TForm1;    NetShareEnum :function (pszServer : PChar; 
                                 sLevel : Cardinal; 
                                 pbBuffer : PChar; 
                                 cbBuffer : Cardinal;
                                 pcEntriesRead, 
                                 pcTotalAvail : Pointer   ):DWORD; stdcall;   NetShareEnumNT :function (ServerName :PWChar;
                                 Level :DWORD;
                                 Bufptr :Pointer;
                                 Prefmaxlen :DWORD;
                                 EntriesRead,
                                 TotalEntries,
                                 resume_handle:LPDWORD): DWORD; stdcall;implementation{$R *.dfm}
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      i:Integer;
      FLibHandle : THandle;
      ShareNT : PShareInfo2Array;
      entriesread,totalentries:DWORD;
      Share : array [0..512] of TShareInfo50;
      pcEntriesRead,pcTotalAvail:Word;
      OS: Boolean;
    begin
       lbxShares.Items.Clear;
      //if not IsNT(OS) then Close;
      if OS then begin
        FLibHandle := LoadLibrary('NETAPI32.DLL');
        if FLibHandle = 0 then Exit;
        @NetShareEnumNT := GetProcAddress(FLibHandle,'NetShareEnum');
        if not Assigned(NetShareEnumNT) then
        begin
          FreeLibrary(FLibHandle);
          Exit;
        end;
        ShareNT := nil;
        if NetShareEnumNT(nil,2,@ShareNT,DWORD(-1),
                 @entriesread,@totalentries,nil) <> 0 then
        begin
          FreeLibrary(FLibHandle);
          Exit;
        end;
        if entriesread > 0 then
        for i:= 0 to entriesread - 1 do
        begin
          lbxShares.Items.Add(String(ShareNT^[i].shi2_netname));
          lbxShares.Items.Add(String(ShareNT^[i].shi2_path));
          lbxShares.Items.Add(IntToStr(ShareNT^[i].shi2_permissions));
          {
          shi2_permissions      Specifies 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.      Value Meaning
          ACCESS_READ Permission to read data from a resource and, by default, to execute the resource.
          ACCESS_WRITE Permission to write data to the resource.
          ACCESS_CREATE Permission to create an instance of the resource (such as a file); data can be written to the resource as the resource is created.
          ACCESS_EXEC Permission to execute the resource.
          ACCESS_DELETE Permission to delete the resource.
          ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified).
          ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.
          ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions.
          }
        end;  end else begin
        FLibHandle := LoadLibrary('SVRAPI.DLL');
        if FLibHandle = 0 then Exit;
        @NetShareEnum := GetProcAddress(FLibHandle,'NetShareEnum');
        if not Assigned(NetShareEnum) then
        begin
          FreeLibrary(FLibHandle);
          Exit; 
        end;
        if NetShareEnum(nil,50,@Share,SizeOf(Share),
                @pcEntriesRead,@pcTotalAvail) <> 0 then
        begin
          FreeLibrary(FLibHandle);
          Exit;
        end;
        if pcEntriesRead > 0 then
        for i:= 0 to pcEntriesRead - 1 do
          lbxShares.Items.Add(String(Share[i].shi50_netname));
      end;
      FreeLibrary(FLibHandle);
    end;end.