Solved

network-checking under windows2000

Posted on 2001-07-25
3
313 Views
Last Modified: 2010-04-06
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
Comment
Question by:Lmoen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 150 total points
ID: 6319575
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
 
LVL 20

Expert Comment

by:Madshi
ID: 6319576
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
 

Author Comment

by:Lmoen
ID: 6322138
thanks for the help
appreciated
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 134
Delphi Mdi application Child forms get behind control 7 306
Delphi 2 77
Installshield for Embarcadero EX 10.1 Berlin 4 72
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question