4

i've got a problem mapping a network drive (WebDAV) under Windows XP using API method WNetAddConnection2. Under Windows 7 or it works like a charme. My code:

function ConnectDrive(Drive: string; Folder: string;
Username: string; Password: string; RestoreAtLogon: Boolean): HRESULT;

var
  NetResource: TNetResource;
  dwFlags: DWORD;
begin
  with NetResource do
  begin
    dwType := RESOURCETYPE_DISK;
    lpLocalName := PChar(Drive);
    lpRemoteName := PChar(Folder);
    lpProvider := nil;
  end;

  if (RestoreAtLogon) then
    dwFlags := CONNECT_UPDATE_PROFILE
  else
    dwFlags := 0;

  Result := WNetAddConnection2(NetResource, PChar(Password),
    PChar(Username), dwFlags);
end;

Everytime i try to connect Windows tells me: "The Network name cannot be found" or "The Network path cannot be found"

As i said before, under Windows 7 there is no problem.

If i use commercial tools like Netdrive, this program has no problem mounting the drive under XP, Vista or Windows 7.

Has anyone an idea?

Thanks in advance

TLama
  • 75,147
  • 17
  • 214
  • 392
Action Heinz
  • 722
  • 10
  • 23
  • I tested your code on a Windows XP (both Home Edition and Professional) machine, and it mapped the network drive as it should (the function returned 0). Could you show an example of how you call the function? – Chris Jun 24 '12 at 15:30
  • I call the function that way: hr := ConnectDrive("M:", "http://myserver/WebDAV", "testuser1", "password", false); – Action Heinz Jun 24 '12 at 15:41
  • 3
    Try it with `'\\myserver\WebDAV'` instead (in case the path is local) – Chris Jun 24 '12 at 15:43
  • Unfortunately this doens'nt help, in which the path is not local, it was just mant as a placeholder for a server. – Action Heinz Jun 24 '12 at 16:05
  • Did you try it by IP? Had a similar weird issue and had to do it by IP. – John Jun 25 '12 at 01:35
  • Yes i've tried it with the ip but the error message is exactly the same. I fear that this could be a driver issue and programs like netdrive use their own one. – Action Heinz Jun 25 '12 at 06:33

1 Answers1

1

There may be countless reasons for your problems...But you can try:

  • The most important thing: fully patch your windows installation (Windows Update - latest SP & updates). You can fight with a bug that can have been fixed (webdav-redirector-list)
  • Ensure you are able to resolve webdav server's name (are you using netbios (wins), dns, hosts file?)
  • Specify FQDN
  • Specify IP Address
  • Try using http://servername or httpS(if supported) instead of UNC (\\servername)
  • Try using NET USE command to see if it succeeds with the mapping (Mapping WebDAV folder as a network drive letter)
  • Check the authentication configuration at IIS Level (Mapping a WebDav network drive)
  • Check these workarrounds: WebDav@Wikipedia
  • Use a network sniffer to capture and analyse the network traffic during the failure (WireShark, Network Monitor etc.)

Hope this helps!

iPath ツ
  • 2,468
  • 20
  • 31