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

x
?
Solved

Connect to network drive and force connect

Posted on 2000-02-28
3
Medium Priority
?
187 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 400 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

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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

885 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