Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Connect to network drive and force connect

Posted on 2000-02-28
3
Medium Priority
?
186 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
[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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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