Solved

reconnecting netdrives

Posted on 2006-06-28
9
412 Views
Last Modified: 2010-04-05
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
Comment
Question by:Jester03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17005392
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
 

Author Comment

by:Jester03
ID: 17007289
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
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17007301
I suggest to use full server path instead of accessing it through mapped drives. e.g.
\\MyServer\MyShare\FileToAccess
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Jester03
ID: 17007348
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
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17007429
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
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17007459
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
 

Author Comment

by:Jester03
ID: 17007542
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
 
LVL 10

Accepted Solution

by:
atul_parmar earned 300 total points
ID: 17007544
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
 

Author Comment

by:Jester03
ID: 17026268
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month3 days, 21 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question