核心提示:function MapNetworkDrive(const handle : THandle; const uncPath : string) : string;//returns mapped d...
function MapNetworkDrive(const handle : THandle; const uncPath : string) : string;//returns mapped drive ("z:") on success
//or uncPath on failure / cancel
var
cds : TConnectDlgStruct;
netResource : TNetResource;
begin
result := uncPath;
ZeroMemory(@netResource, SizeOf(TNetResource)) ;
netResource.dwType := RESOURCETYPE_DISK;
netResource.lpRemoteName := PChar(uncPath) ;
cds.cbStructure := SizeOf(TConnectDlgStruct) ;
cds.hwndOwner := handle;
cds.lpConnRes := @netResource;
cds.dwFlags := CONNDLG_PERSIST;
if WNetConnectionDialog1(cds) = NO_ERROR then
begin
result := Chr(-1 + Ord('A') + cds.dwDevNum) + DriveDelim;
end;
end;
用法:MapNetworkDrive(Application.Handle, '\\server\shared-folder');