Solved

network-checking under windows2000

Posted on 2001-07-25
3
317 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

742 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