Solved

Connect to network drive and force connect

Posted on 2000-02-28
3
181 Views
Last Modified: 2010-04-04
Many thanks for last question,

let's say if i'am going to connect network drive K: with \\Server, but
this char K: is already connected ( taken ),

so i'am wondering if i can connect to another network drive with theese drive letter K: ?

Points..........Points..........Points..........Points..........Points..........

Esk
0
Comment
Question by:esk
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2564755
hi,
only if you first unmap the drive that is currently connected..
something like this:

first it checks who is connected then if not \\server3\f_drive then disconnects them and maps server3\f_drive instead.


procedure TForm1.Button3Click(Sender: TObject);
var
NetResource: TNetResource;
buf : array [0..100] of char;
i :cardinal;
 begin
i := 100;
wnetgetconnection('K:',buf,i);
if buf = '\\server2\C_drive'
then begin
label1.caption :=
'unmapping drive cause its not server3\_f_drive';
if not
WNetCancelConnection2('K:', CONNECT_UPDATE_PROFILE, True) <> 0
then label1.caption :=SysErrorMessage(GetLastError);
NetResource.dwScope      := RESOURCE_GLOBALNET;
NetResource.dwType       := RESOURCETYPE_DISK;
NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_DOMAIN;
NetResource.dwUsage      := RESOURCEUSAGE_CONNECTABLE;
NetResource.lpLocalName  := 'K:';
NetResource.lpRemoteName :=
'\\server3\F_drive';
NetResource.lpComment    := 'For testing purposes';
NetResource.lpProvider   := '';
WNetAddConnection2(NetResource,'','',CONNECT_UPDATE_PROFILE);
   end
else if
 buf = '\\server3\F_drive' then
label1.caption :='k: is already  mapped to \\server3\F_drive';
end;

hope it helps some
Regards Barry
0
 
LVL 17

Expert Comment

by:inthe
ID: 2564759
sorry this line should be changed :
if buf = '\\server2\C_drive'
to something like
if not buf = '\\server2\C_drive' ...
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2569158
esk, you can try to call 'net use * \\myserver\myDir' via Createprocess or ShellExecute, this will try to connect you to NEXT AVAILABLE local driver letter


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

22 Experts available now in Live!

Get 1:1 Help Now