Solved

Connect to network drive and force connect

Posted on 2000-02-28
3
182 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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