Home > Back-end >  DELPHI XE2 through WNetAddConnection2 mapping a network drive
DELPHI XE2 through WNetAddConnection2 mapping a network drive

Time:11-15

Test environment, DELPHI XE2 version, system WIN10
Set up process
Procedure TForm1. D (const driver, remote, pass, name: string).
Var netsource: TNetResource;
The begin
With netsource do
The begin
DwType:=RESOURCETYPE_ANY;
LpLocalName:=PwideChar (driver);
LpRemoteName:=PWideChar (remote);
LpProvider:=';
end;
WNetAddConnection2 (netsource, PWideChar (pass), PWideChar (name), CONNECT_UPDATE_PROFILE);
end;
Call the process
Procedure TForm1. Button5Click (Sender: TObject);
The begin
D (x ':', '\ \ 172.16.0.20 \ pro,' 123456 ', 'CD \ 10001');
end;

Driver for the mapped drive letter, remote network mapping path, pass as the password, the name for the domain account
After running, mapping out all the time, using DOS.net can use, but now want to use this function to implement, have a great god give some advice,

CodePudding user response:

How no one back

CodePudding user response:

First of all, if you have the same mapping connection, are not allowed to connect again, you'd better try to empty all the mapping test again after the following code:
 
Procedure TForm1. D (const FDriver FRemote, FPass, FUserName: string).
Var
FNetSource: TNetResource;
The begin
FillChar (FNetSource, SizeOf (FNetSource), 0).
With FNetSource do
The begin
DwScope:=RESOURCE_REMEMBERED or RESOURCETYPE_DISK;
DwType:=RESOURCETYPE_ANY;
LpLocalName:=PChar (FDriver);
LpRemoteName:=PChar (FRemote);
LpProvider:=nil;
end;
If WNetAddConnection2 (FNetSource, PChar (FPass), PChar (FUserName),
CONNECT_UPDATE_PROFILE) & lt;> 0 then
ShowMessage (SysErrorMessage GetLastError ());
end;

  • Related