[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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



0
trausti
Asked:
trausti
  • 6
  • 5
1 Solution
 
intheCommented:
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
0
 
traustiAuthor Commented:
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?
0
 
traustiAuthor Commented:
and of course i need to be able to disconnect the drive

thanks
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
intheCommented:
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)
0
 
traustiAuthor Commented:
what does the "Buf"?
0
 
intheCommented:
DWORD WNetGetConnection(
LPCTSTR lpLocalName,// pointer to local name
LPTSTR lpRemoteName,// pointer to buffer for remote name
LPDWORD lpnLength // pointer to buffer size, in characters  
   );
0
 
traustiAuthor Commented:
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
0
 
intheCommented:
ok,
you want something like this which uses all the apis above to map a connection :

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
//showmessage('unmapping drive');
if not
WNetCancelConnection2('K:', CONNECT_UPDATE_PROFILE, True) <> 0
then showmessage(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
showmessage('k: is already  mapped to \\server3\F_drive');
end;

hope this is what your after
Regards Barry
0
 
traustiAuthor Commented:
error:

"this network connection does not exists"
0
 
intheCommented:
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


0
 
traustiAuthor Commented:
Hi! i test is better and it works, my fault

thanks
Trausti
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now