Solved

reconnecting netdrives

Posted on 2006-06-28
9
402 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
  • 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now