Подключение сетевого диска при нажатии на кнопку Button.
Unit1.cpp
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { NETRESOURCE nd; ZeroMemory (&nd, sizeof(nd)); nd.dwType=RESOURCETYPE_DISK; nd.lpLocalName="Z:"; //Буква диска nd.lpRemoteName="\\\\192.168.100.88\\E"; //IP компа с расширенной папкой E. Вместо IP можно писать доменное имя. WNetAddConnection2A(&nd,"000","3",NULL); //000-пароль к папке Е, 3-логин к папке E } //---------------------------------------------------------------------------
Unit1.h
//--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif