[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

network-checking under windows2000

Hello.  I want to display a list of shared resources (directories, and perhaps devices) in a Delphi program I'm writing for Windows2000.

I first tried the 'WNETConnectionDialog(x)' command, but it's not supported under win32's.

Then I tried 'netsharegetinfo' but it's also not supported in win32, and it's a LanManager function, and not an API one.

How can I do what I want to do under Windows2000?  Any examples would be appreciated.  I've basically read through the (WNET) WINDOWS NETWORKING section of win32.hlp but couldn't find something that might be of help.

Any suggestions?
Thanks in advance
0
Lmoen
Asked:
Lmoen
1 Solution
 
intheCommented:
hi,
some examples (WNetEnumResource,WNetOpenEnum):

into treeview:

http://www.delphifreestuff.com/examples/wnetexmp.zip

into listbox:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure EnumRemoteDrives(Items: TStringlist);
function EnumerateFunc(lpnr: PNetResource; Items: TStringList; DrillDepth: Integer): Boolean;
var
lpnrLocal: PNetResource;
hEnum:THandle;
dwResult, dwResultEnum, cbBuffer, cEntries: DWORD;
i: Integer;
p1:PChar;
p2:PnetResource;
s, t: string;
begin
dwResult := WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK, 0, lpnr, hEnum);
if dwResult <> NO_ERROR then begin EnumerateFunc := False;
 exit;
  end;
cbBuffer := 32768;
cEntries := $FFFFFFFF;
lpnrLocal := PNetResource(GlobalAlloc(GPTR,cbBuffer));
repeat
dwResultEnum := WNetEnumResource(hEnum,cEntries, lpnrLocal, cbBuffer);
if dwResultEnum = NO_ERROR then begin
for i := 0 to cEntries - 1 do begin
p1 := PChar(lpnrLocal) + i *
SizeOf(TNetResource);
p2 := PNetResource(p1);
s := StrPas(p2^.lpRemoteName);
if Length(s) > 2 then
if (s[1] = '\') and
(s[2] = '\') then begin
t := Copy(s,
3, Length(s) - 2);
if Pos('\', t)
<> 0 then
items.Add(s);
end;
if (p2.dwUsage and RESOURCEUSAGE_CONTAINER) = RESOURCEUSAGE_CONTAINER then
if DrillDepth < 3 then
EnumerateFunc(p2, Items, DrillDepth + 1);
end;
end;
until dwResultEnum = ERROR_NO_MORE_ITEMS;
GlobalFree(HGLOBAL(lpnrLocal));
dwResult := WNetCloseEnum(hEnum);
if dwResult <> NO_ERROR then begin EnumerateFunc := False;
 exit;
  end;
EnumerateFunc := True;
end;
begin
EnumerateFunc(nil, Items, 0);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
sl : tstringlist;
begin
sl := tstringlist.create;
EnumRemoteDrives(sl);
listbox1.items.addstrings(sl);
sl.free;
end;

end.


others for actually mapping and checking mapped drives are WNetAddConnection , WNetGetConnection,WNetCancelConnection
0
 
MadshiCommented:
Don't trust Delphi's win32.hlp file. It's outdated in some areas and even *wrong* in others. NetShareGetInfo is absolutely supported. The correct API is NetShareEnum:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/hh/network/ntlmapi2_4l2l.asp

Regards, Madshi.
0
 
LmoenAuthor Commented:
thanks for the help
appreciated
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now