Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

lanmanager api example(s) wanted

Posted on 2002-06-16
3
Medium Priority
?
176 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 400 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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