Get list of network drives

Posted in Files & folders

To get list of all network drives, use WNetGetConnection function.

procedure TForm1.Button1Click(Sender: TObject);
var
  Drive: Char;
  PathStr: array[0..MAX_PATH] of Char;
  LPathStr: DWord;
begin
  LPathStr:=MAX_PATH;
  with Memo1.Lines do
  begin
    Clear;
    for Drive:='A' to 'Z' do
      if WNetGetConnection(
        PChar(''+Drive+':'), 
        PathStr, 
        LPathStr)=NO_ERROR then Add(Drive);
    if Count=0 then
      Add('You have not network drives');
  end;
end;