Registriert seit: 10. Apr 2006
Ort: Leverkusen
969 Beiträge
Delphi 6 Professional
|
AW: Netzwerkordnerzugriff
29. Jun 2018, 13:33
Hmm..
Kann Dir nur Auszüge geben:
Delphi-Quellcode:
function IsLocalPath(const Path:string):boolean;
var
i : cardinal;
begin
i := GetDriveType(pchar(copy(path,1,2)));
result := (i = DRIVE_FIXED) or
(i = DRIVE_CDROM) or
(i = DRIVE_RAMDISK) or
(i = DRIVE_REMOVABLE);
end;
function Logout(Path:String):Cardinal;
begin
result := NO_ERROR;
if length(path) > 0 then begin
if path[1] = '\' then begin
path := ExcludeTrailingPathDelimiter(ExpandUNCFileName(Trim(path)));
// Windows-Share LogOff
result := WNetCancelConnection2(pchar(Path),CONNECT_UPDATE_PROFILE,true);
// NetWare-Server LogOff nur mit dem Server-Namen!
path := '\\' + ExtractServerName(path);
WNetCancelConnection2(pchar(copy(Path,3,length(path)-2)),CONNECT_UPDATE_PROFILE,true);
end else begin
result := WNetCancelConnection2(pchar(Path),CONNECT_UPDATE_PROFILE,true);
end;
end;
end;
function Logon(Drive, Path, User, Password:String; TemporaryOnly : boolean):Cardinal;
var
NetRes : TNetResource;
tempres : Cardinal;
dwFlags : Cardinal;
begin
if islocalpath(path) then
tempres := NO_ERROR //No need to logon
else begin
path := ExcludeTrailingPathDelimiter(ExpandUNCFileName(Trim(path)));
// Windows-Share login
NetRes.dwScope := RESOURCE_GLOBALNET;
NetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;//RESOURCEDISPLAYTYPE_GENERIC;
NetRes.dwUsage := RESOURCEUSAGE_CONNECTABLE;
NetRes.lpComment := '';
// Nur diese Angaben sind notwendig..
NetRes.dwType := RESOURCETYPE_DISK; // RESOURCETYPE_ANY;
NetRes.lpLocalName := pchar(Drive);
NetRes.lpRemoteName := pchar(path);
NetRes.lpProvider := '';
if TemporaryOnly then
dwFlags := CONNECT_TEMPORARY // 0
else
dwFlags := CONNECT_UPDATE_PROFILE;
// CONNECT_UPDATE_RECENT ?
if User = '' then
tempres := WNetAddConnection2(NetRes, nil, nil, dwFlags)
else
tempres := WNetAddConnection2(NetRes, pchar(Password), pchar(User), dwFlags);
end;
result := tempres;
end;
Verbindung herstellen / LW Mappen:
Delphi-Quellcode:
procedure TForm1.ButtonAddNetUseClick(Sender: TObject);
var
err : DWORD;
begin
err := Logon(EditLocalDrive.Text, EditShare.Text,EditUser.Text,EditPassword.Text,true);
if err <> 0 then
ShowMessage(IntToStr(err) + ' - ' + SysErrorMessage(err));
end;
Öffen des UNC-PFades im Explorer:
ShellExecute(self.Handle, nil, PChar(AUNCPath),nil,nil,SW_SHOW);
(Erstellt mit D6, eventuell Anpassungen an UniCode notwendig)
|
|
Zitat
|