Link to home
Start Free TrialLog in
Avatar of trausti
trausti

asked on

WNetAddConnection Dialog


hello experts, long time no see

here is one quesion from me:

is possible to connect to this dialog and return computer_name into editbox oris available any component to do this: browse the network neighborhood
and return parameter with the computer name?

regards
Trausti



Avatar of inthe
inthe

you an call the dialog directly like:

procedure TForm1.Button2Click(Sender: TObject);
begin
  WNetConnectionDialog(Handle,RESOURCETYPE_DISK);
   {RESOURCETYPE_PRINT for printer}
end;

or do it in code:

procedure TForm1.Button3Click(Sender: TObject);
var
 NetResource: TNetResource;
  begin
  { fill our TNetResource record structure }
 NetResource.dwType       := RESOURCETYPE_DISK;
 NetResource.lpLocalName  := 'S:';
 NetResource.lpRemoteName := '\\server\public';
 NetResource.lpProvider   := '';
{ map our network drive using our TNetResource
 record structure }
 WNetAddConnection2(NetResource,
      '', {Clave o vacio /Password or empty}
      '', {Nombre del usurio o vacio/User name o vacio}
 CONNECT_UPDATE_PROFILE);
   end;
{In that example, we will connect '\\server\public' to S:,
 without username neither password }

if you want to enum the network computers see this project:
http://www.delphifreestuff.com/examples/wnetexmp.zip

Regards Barry
Avatar of trausti

ASKER

can i not use the dialog and get value back, computer.name?

we should say if i have connected drive with letter k: and i want to add new share on another computer with the share name k:, how is it possible?
Avatar of trausti

ASKER

and of course i need to be able to disconnect the drive

thanks
hi,
im not positive but  maybe your after wnetgetconnection instead :
var
  Value: DWord;
  i: Integer; //or cardinal
  Buf: array[0..100] of Char;
begin
 iLen := 100;
 Value := WNetGetConnection('X:',Buf,i);
end;

to cancel it use WNetCancelConnection2('LPT1', CONNECT_UPDATE_PROFILE, True)
Avatar of trausti

ASKER

what does the "Buf"?
DWORD WNetGetConnection(
LPCTSTR lpLocalName,// pointer to local name
LPTSTR lpRemoteName,// pointer to buffer for remote name
LPDWORD lpnLength // pointer to buffer size, in characters  
   );
Avatar of trausti

ASKER

i have a drive letter(K) connected with my server, i want connect to another server and i want to use the drive letter (K) same, how is that possible?
override the drive letter?

Yes!!! Barry
Trausti
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trausti

ASKER

error:

"this network connection does not exists"
well i dont know where you get that error so if its here:
if buf = '\\server2\C_drive'
then begin
//showmessage('unmapping drive');
if not
WNetCancelConnection2('K:', CONNECT_UPDATE_PROFILE, True) <> 0
then showmessage(SysErrorMessage(GetLastError)); //<--this error you mean?

if you got this far then it mean k: was mapped to the path you have in buf.so unless the connection exists it shouldnt get to the code the does the unmapping ..so i dont see how you could have got that error.
have you changed the code much ?
are you typing the share name correctly?
btw you dont need the error check code you can delete it  so its just

or if the error is when mapping the new drive only reasn can be spelling the drive share name wrong
lpRemoteName := '\\yourserver\F_on_nt';
is my share name for my f drive on nt machine ..
maybe if you post the code your using or something..
can email it if you wish to
borgsAssimilate@aol.com
might be clearer to see whats happening..
cheers Barry


Avatar of trausti

ASKER

Hi! i test is better and it works, my fault

thanks
Trausti