Solved

Connect to network drive and force connect

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

17 Experts available now in Live!

Get 1:1 Help Now