Article View: be.comp.programming
Article #17452Re: Windows shares
From: Ares Lagae
Date: Thu, 16 Dec 1999 00:00
Date: Thu, 16 Dec 1999 00:00
162 lines
5189 bytes
5189 bytes
Intussen heb ik het gevonden. Voorbeeld in Delphi:
----------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, ExtCtrls, WNet;
type
TForm1 = class(TForm)
Panel1: TPanel;
LabelUNCPath: TLabel;
LabelPassword: TLabel;
EditUNCPath: TEdit;
EditPassword: TEdit;
ButtonConnectServer: TButton;
procedure ButtonConnectServerClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ButtonConnectServerClick(Sender: TObject);
Var ErrCode: DWORD;
ErrStr: String;
begin
ErrCode := ConnectServer(PChar(EditUNCPath.Text),
PCHar(EditPassword.Text));
ErrStr := GetError(ErrCode);
MessageDlg('Result: ' + ErrStr, mtInformation, [mbok], 0);
end;
end.
-----------------------------------
unit WNet;
interface
uses windows;
const
// return codes
NO_ERROR = 0;
ERROR_ACCESS_DENIED = 5;
ERROR_ALREADY_ASSIGNED = 85;
ERROR_BAD_DEV_TYPE = 66;
ERROR_BAD_DEVICE = 1200;
ERROR_BAD_NET_NAME = 67;
ERROR_BAD_PROFILE = 1206;
ERROR_BAD_PROVIDER = 1204;
ERROR_BUSY = 170;
ERROR_CANNOT_OPEN_PROFILE = 1205;
ERROR_DEVICE_ALREADY_REMEMBERED = 1202;
ERROR_EXTENDED_ERROR = 1208;
ERROR_INVALID_PASSWORD = 86;
ERROR_NO_NET_OR_BAD_PATH = 1203;
ERROR_NO_NETWORK = 1222;
//connection type constants
RESOURCE_PUBLICNET = $2;
RESOURCEDISPLAYTYPE_DOMAIN = $1;
RESOURCEDISPLAYTYPE_FILE = $4;
RESOURCEDISPLAYTYPE_GENERIC = $0;
RESOURCEDISPLAYTYPE_GROUP = $5;
RESOURCEDISPLAYTYPE_SERVER = $2;
RESOURCEDISPLAYTYPE_SHARE = $3;
RESOURCETYPE_ANY = $0;
RESOURCETYPE_DISK = $1;
RESOURCETYPE_PRINT = $2;
RESOURCETYPE_UNKNOWN = $FFFF;
RESOURCEUSAGE_CONNECTABLE = $1;
RESOURCEUSAGE_CONTAINER = $2;
RESOURCEUSAGE_RESERVED = $80000000;
// This function will connect to a network resource. It will attach to
the server and make it
// appear in your network neighbourhood listing, rather than in the
Entire Network section.
// remote name = \\server_name\volume
function ConnectServer(RemoteName, Password: PChar): DWord;
// This function returns a string as error information
Function GetError(Error: DWORD): string;
implementation
uses SysUtils;
Function GetError(Error: DWORD): string;
begin
case error of
NO_ERROR: result := 'No error';
ERROR_ACCESS_DENIED: result := 'Acces denied';
ERROR_ALREADY_ASSIGNED: result := 'Already assigned';
ERROR_BAD_DEV_TYPE: result := 'Bed device type';
ERROR_BAD_DEVICE: result := 'Bad device';
ERROR_BAD_NET_NAME: result := 'Bad net name';
ERROR_BAD_PROFILE: result := 'Bad profile';
ERROR_BAD_PROVIDER: result := 'Bad provider';
ERROR_BUSY: result := 'Busy';
ERROR_CANNOT_OPEN_PROFILE: result := 'Cannot open profile';
ERROR_DEVICE_ALREADY_REMEMBERED: result := 'Device already
remembered';
ERROR_EXTENDED_ERROR: result := 'Extended error';
ERROR_INVALID_PASSWORD: result := 'Invalid password';
ERROR_NO_NET_OR_BAD_PATH: result := 'No net or bad result';
ERROR_NO_NETWORK: result := 'No network';
else result := 'Error unknown (' + inttostr(Error) + ')';
end;
end;
// This routine will connect to a network resource. It will attach to
the server and make it
// appear in your network neighbourhood listing, rather than in the
Entire Network section.
// remote name = \\server_name\volume
function ConnectServer(RemoteName, Password: PChar): DWord;
var NetRes: TNetResourceA;
Comment: String;
ErrCode: DWORD;
begin
Comment := ' ' + chr(255);
NetRes.dwScope := RESOURCE_PUBLICNET;
NetRes.dwType := RESOURCETYPE_ANY;
NetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
NetRes.dwUsage := RESOURCEUSAGE_CONTAINER;
NetRes.lpLocalName := chr(0);
NetRes.lpRemoteName := RemoteName;
NetRes.lpComment := PChar(Comment);
NetRes.lpProvider := chr(0);
ErrCode := WNetAddConnection2(NetRes, Password, PChar(''), 0);
result := ErrCode;
end;
end.
------------------------------
Ares Lagae wrote:
> Weet iemand hoe je (mbv api-calls) met shared directories werkt?
> in delphi, vb, visual c, ... whatever
>
> Groetjes,
> Ares
Technical Details
Message-ID:
<3858CA54.79D62636@student.kulak.ac.be>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3857F4B4.26287AD3@student.kulak.ac.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,6953385c33666850 X-Google-Attributes: gidfcea4,public From: Ares Lagae <ares.lagae@student.kulak.ac.be> Subject: Re: Windows shares Date: 1999/12/16 Message-ID: <3858CA54.79D62636@student.kulak.ac.be> X-Deja-AN: 561458059 Cache-Post-Path: marvin!unknown@pc-10-1-0-089.kulak.ac.be Content-Transfer-Encoding: 7bit References: <3857F4B4.26287AD3@student.kulak.ac.be> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@belnet.be X-Trace: naxos.belnet.be 945342983 14482 134.58.127.3 (16 Dec 1999 11:16:23 GMT) Organization: KULeuvenNet X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) Mime-Version: 1.0 NNTP-Posting-Date: 16 Dec 1999 11:16:23 GMT Newsgroups: be.comp.programming