Solved

reconnecting netdrives

Posted on 2006-06-28
9
406 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

790 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