试着写了一个简单的网络映射程序

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Data_Year: TComboBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    NetSource: TNetResource;
    ErrInfo   :   Longint;
begin
    With  NetSource DO
      begin
          dwType := RESOURCETYPE_ANY;
          lpLocalName   :=   Pchar('Z:');   //网络驱动器编号
          Case Data_year.ItemIndex Of
               0:lpRemoteName := PChar('\\111.111.111.2\xx08$');
               1:lpRemoteName := PChar('\\111.111.111.2\xx07$');
               2:lpRemoteName := PChar('\\111.111.111.2\xx06$');
               3:lpRemoteName := PChar('\\111.111.111.2\xx05$');
               4:lpRemoteName := PChar('\\111.111.111.2\xx$');              
          End;
          lpProvider := '';
       WNetCancelConnection2(pchar(lpLocalName), CONNECT_UPDATE_PROFILE, True);//先断开原有的
       ErrInfo := WNetAddConnection2(NetSource,'',Pchar('user'),CONNECT_UPDATE_PROFILE);
      If   ErrInfo = NO_ERROR   Then
          MessageBox(0,'映射成功','',0)
      Else
          MessageBox(0,'映射失败','',0);
      end;
  end;

end.

 

//书已经看到92页

posted @ 2009-04-28 11:18  QS_SH  阅读(309)  评论(1编辑  收藏  举报