Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

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.
0
Jester03
Asked:
Jester03
  • 4
  • 4
1 Solution
 
TheRealLokiCommented:
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.
0
 
Jester03Author Commented:
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.
0
 
atul_parmarCommented:
I suggest to use full server path instead of accessing it through mapped drives. e.g.
\\MyServer\MyShare\FileToAccess
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Jester03Author Commented:
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?
0
 
atul_parmarCommented:
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 http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21668715.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.
0
 
atul_parmarCommented:
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;





0
 
Jester03Author Commented:
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.
0
 
atul_parmarCommented:
If you plan to use WNetAddConnection2, you need to disconnect first otherwise you will get an error while you execute WNetAddConnection2. To disconnect, you can use the following function.
  WNetCancelConnection2('X:', 0, False);
0
 
Jester03Author Commented:
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.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now