Solved

lanmanager api example(s) wanted

Posted on 2002-06-16
3
169 Views
Last Modified: 2010-04-04
just wondering if anyone has any examples to do with connecting to a remote share with NetShareAdd and/or enumerating remote shares with NetShareEnum. thanks.
0
Comment
Question by:freedumb
3 Comments
 
LVL 4

Accepted Solution

by:
nestorua earned 100 total points
ID: 7082044
HI, freedumb,
I found in my projects (don't forget from where) something that maybe is of any use and interest for you.
Here it is:

unit frmMain;

interface

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

type
  TFormMain = class(TForm)
    Button3: TButton;
    Memo1: TMemo;
    procedure Button3Click(Sender: TObject);
  private
    function EnumerateFunc(hwnd: HWND; hdc: HDC;
      lpnr: PNetResource): Boolean;
    { Private declarations }
  public
    a: longint;
    procedure TestWndProc(var Message: TMessage);
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.DFM}


procedure TFormMain.TestWndProc(var Message: TMessage);
begin
end;

function TFormMain.EnumerateFunc( hwnd: HWND; hdc: HDC ; lpnr: PNetResource ): Boolean;
const
  cbBuffer : DWORD  = 16384;      // 16K is a good size
var
  hEnum, dwResult, dwResultEnum : DWORD;
  lpnrLocal : array
        [0..16384 div SizeOf(TNetResource)] of TNetResource;    // pointer to enumerated structures
  i : integer;
  cEntries : Longint;
begin
  centries := -1;    // enumerate all possible entries

  // Call the WNetOpenEnum function to begin the enumeration.
  dwResult := WNetOpenEnum(
                          RESOURCE_CONTEXT,  // Enumerate currently connected resources.
                          RESOURCETYPE_DISK, // all resources
                          0,                 // enumerate all resources
                          lpnr,              // NULL first time the function is called
                          hEnum              // handle to the resource
                          );

  if (dwResult <> NO_ERROR) then
  begin
    // Process errors with an application-defined error handler
    Result := False;
    Exit;
  end;

  // Initialize the buffer.
  FillChar( lpnrLocal, cbBuffer, 0 );

  // Call the WNetEnumResource function to continue
  //  the enumeration.
  dwResultEnum := WNetEnumResource(hEnum, // resource handle
                                  DWORD(cEntries),
 // defined locally as -1
                                  @lpnrLocal,
// LPNETRESOURCE
                                  cbBuffer); // buffer size

  // This is just printing
  for i := 0 to cEntries - 1 do
  begin
    // loop through each structure and
    // get remote name of resource... lpnrLocal[i].lpRemoteName)
    Memo1.Lines.Add(lpnrLocal[i].lpRemoteName);
  end;

  // Call WNetCloseEnum to end the enumeration.
  dwResult := WNetCloseEnum(hEnum);

  if(dwResult <> NO_ERROR) then
  begin
    // Process errors... some user defined function here
    Result := False;
  end
  else
    Result :=  True;
end;

procedure TFormMain.Button3Click(Sender: TObject);
var  wnd: HWND;
      dc: HDC ;
     lpnr: PNetResource;
begin
 lpnr:=NIL;
 EnumerateFunc(wnd, dc, lpnr);
end;

end.

Sincerely,
Nestorua.
0
 

Expert Comment

by:CleanupPing
ID: 9343198
freedumb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9453374
freedumb,
No comment has been added lately (17 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to nestorua http:#7082044

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now