Link to home
Start Free TrialLog in
Avatar of Member_2_1123121
Member_2_1123121

asked on

reconnecting netdrives

Hello,

I have the following problem with networks in general:

Currently there are 3 netdrives attached to my Windows Explorer, that are automatically reconnected when I start the computer. Let´s assume these netdrives are X:, Y: and Z:. Right after Windows XP is up and running, I am able to click on these drives in Explorer and I can access the content of the server. So far, so good.
But what is not working, is when I try to access these drives (right after system start) for example with a self written program (launched by autostart) that needs to access specific files on the above mentioned netdrives. The program does not find these drives, as if they were not reconnected. The only workaround for my program in order to recognize the drives is to start Windows Explorer and click on the netdrives with the left mouse button.
Other example:
I am using Thunderbird in the office and the e-mail account uses a signature which is stored on netdrive Z:. Unless I do not click at least once on the netdrive in Windows Explorer after system startup, Windows does not seem to recognize that it is there. Hence Thunderbird is not able to attach my signature. No problem occurs when you open any file via the open menu in any program. It only happens when you directly attempt to access a file or a netdrive in general right after the system has started.

So if there is a workaround I can use with delphi or directly in Windows I would be very happy.
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

some services can start before the network is truely ready
I do not know what "autostart" is, but if it is a service, you could add a dependency to it with the network services, so that it does not start until the network is ready.
I think there is a WMNetAddConnection2() or similar command to manually add a connection in delphi. may have changed, haven't used it in over 3 years, so not even sure of the name.
Avatar of Member_2_1123121
Member_2_1123121

ASKER

With "autostart" I mean that the program starts itself when windows has started.

Nevertheless, how far I can see, this is not a problem of a network service. For example if you use Excel and want to open a file via the recent files list the problem appears, too, even after hours. Windows "reconnects" the netdrives in Explorer, I can see their letters. But as long as I do not click them or open a file via the file-open-menu you cannot access these drives with shortcuts, recent file lists or with a programm that attempts to access them directly.
I suggest to use full server path instead of accessing it through mapped drives. e.g.
\\MyServer\MyShare\FileToAccess
Hello atul_parmar,

you are right. When I use the full server path it works without any problems. I have just tested it with the recent-files-list in Excel. But do you know how I can get it to work with the mapped drives. Is there a way to fix it with a small delphi application at system startup?
Hi,

There are several ways and what to choose depends on your choice. One way is to get the full server path from the mapped drive and then use it (as you just did and knows that it works)
see https://www.experts-exchange.com/questions/21668715/Get-share-location-from-mapped-drive-letter.html on how to get full server path from mapped drive

Another way is to reconnect the mapped drive. It is required, because when you logs on window just remembers the mapped connection but does not connects you until you click there.
To reconnect, you can use the following.

var nw:
  TNetResource;
begin
  nw.dwType := RESOURCETYPE_DISK;
  nw.lpLocalName := nil;
  nw.lpRemoteName := PChar('\\MyServer\MyShare');
  nw.lpProvider := nil;
  nw.lpLocalName := 'X:';
  errCode := WNetAddConnection2(nw, nil, nil, 0);
  // If it requires password, then use errCode := WNetAddConnection2(nw, 'strPassword', nil, 0);
  if errCode <> NO_ERROR then
    ShowMessage('Error connecting drive');
end;





Your answer came before I could ask the question ;) Thanks.

Unfortunately I am not able to test it right now. I will do it over the weekend. If it works, you will get the points.

Again, thanks for the fast response.
ASKER CERTIFIED SOLUTION
Avatar of atul_parmar
atul_parmar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello atul_parmar,

all of your above mentioned hints were very useful to me, that is why I accept your last entry as the correct answer. It works.
Thanks again and here are the points.