Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.06.13;
Скачать: CL | DM;

Вниз

Монтирование сетевого диска   Найти похожие ветки 

 
lightix   (2004-04-23 13:02) [0]

Подскажите, как смонтировать\размонтировать сетевой диск, чтобы при монтировании получить его имя ?


 
RAIN ©   (2004-04-23 13:15) [1]

Вот пример:

function ConnectDrive(_drvLetter: string; _netPath: string; _showError: Boolean;
 _reconnect: Boolean): DWORD;
var
 nRes: TNetResource;
 errCode: DWORD;
 dwFlags: DWORD;
begin
 { Fill NetRessource with #0 to provide uninitialized values }
 { NetRessource mit #0 fullen => Keine unitialisierte Werte }
 FillChar(NRes, SizeOf(NRes), #0);
 nRes.dwType := RESOURCETYPE_DISK;
 { Set Driveletter and Networkpath }
 { Laufwerkbuchstabe und Netzwerkpfad setzen }
 nRes.lpLocalName  := PChar(_drvLetter);
 nRes.lpRemoteName := PChar(_netPath); { Example: \\Test\C }
 { Check if it should be saved for use after restart and set flags }
 { Uberprufung, ob gespeichert werden soll }
 if _reconnect then
   dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
 else
   dwFlags := CONNECT_INTERACTIVE;

 errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);
 { Show Errormessage, if flag is set }
 { Fehlernachricht aneigen }
 if (errCode <> NO_ERROR) and (_showError) then
 begin
   Application.MessageBox(PChar("An error occured while connecting:" + #13#10 +
     SysErrorMessage(GetLastError)),
     "Error while connecting!",
     MB_OK);
 end;
 Result := errCode; { NO_ERROR }
end;

function ConnectPrinterDevice(_lptPort: string; _netPath: string; _showError: Boolean;
 _reconnect: Boolean): DWORD;
var
 nRes: TNetResource;
 errCode: DWORD;
 dwFlags: DWORD;
begin
 { Fill NetRessource with #0 to provide uninitialized values }
 { NetRessource mit #0 fullen => Keine unitialisierte Werte }
 FillChar(NRes, SizeOf(NRes), #0);
 nRes.dwType := RESOURCETYPE_PRINT;
 { Set Printername and Networkpath }
 { Druckername und Netzwerkpfad setzen }
 nRes.lpLocalName  := PChar(_lptPort);
 nRes.lpRemoteName := PChar(_netPath); { Example: \\Test\Printer1 }
 { Check if it should be saved for use after restart and set flags }
 { Uberprufung, ob gespeichert werden soll }
 if _reconnect then
   dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
 else
   dwFlags := CONNECT_INTERACTIVE;

 errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);
 { Show Errormessage, if flag is set }
 { Fehlernachricht aneigen }
 if (errCode <> NO_ERROR) and (_showError) then
 begin
   Application.MessageBox(PChar("An error occured while connecting:" + #13#10 +
     SysErrorMessage(GetLastError)),
     "Error while connecting!",
     MB_OK);
 end;
 Result := errCode; { NO_ERROR }
end;

function DisconnectNetDrive(_locDrive: string; _showError: Boolean; _force: Boolean;
 _save: Boolean): DWORD;
var
 dwFlags: DWORD;
 errCode: DWORD;
begin
 { Set dwFlags, if necessary }
 { Setze dwFlags auf gewunschten Wert }
 if _save then
   dwFlags := CONNECT_UPDATE_PROFILE
 else
   dwFlags := 0;
 { Cancel the connection see also at http://www.swissdelphicenter.ch/en/showcode.php?id=391 }
 { Siehe auch oben genannten Link (Netzlaufwerke anzeigen) }
 errCode := WNetCancelConnection2(PChar(_locDrive), dwFlags, _force);
 { Show Errormessage, if flag is set }
 { Fehlernachricht anzeigen }
 if (errCode <> NO_ERROR) and (_showError) then  
 begin
   Application.MessageBox(PChar("An error occured while disconnecting:" + #13#10 +
     SysErrorMessage(GetLastError)),
     "Error while disconnecting",
     MB_OK);
 end;
 Result := errCode; { NO_ERROR }
end;

{Beispiel / Example:}

procedure TForm1.Button1Click(Sender: TObject);
begin
 ConnectDrive("h:", "\\Servername\C", True, True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 DisconnectNetDrive("h:", True, True, True);
end;



Страницы: 1 вся ветка

Текущий архив: 2004.06.13;
Скачать: CL | DM;

Наверх




Память: 0.46 MB
Время: 0.026 c
14-1085503543
Piter
2004-05-25 20:45
2004.06.13
Пиринговые сети


6-1082732730
god
2004-04-23 19:05
2004.06.13
TServerSocket &amp; TClientSocket !!! ReciveText


1-1086156408
Term
2004-06-02 10:06
2004.06.13
Поиск файлов


3-1085126188
Jean
2004-05-21 11:56
2004.06.13
как использовать tranmsform и pivot в BDE ???


3-1085035035
NoName
2004-05-20 10:37
2004.06.13
DBGridEh





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский