Registriert seit: 2. Dez 2009
Ort: München
320 Beiträge
Lazarus
|
Re: Dienst kann kein Netzlaufwerk verbinden...
26. Feb 2010, 22:03
Zitat von Bambuti2000:
Also, wer weitere Ideen hat ist herzlich eingeladen...
Versuch mal dies.
Delphi-Quellcode:
{$APPTYPE CONSOLE}
uses
Sysutils,
Windows;
function ConnectNetworkResource(const networkResource: string; const mappedLetter:
string = ''; const username: string = ''; const password: string = ''): boolean;
var
bufferSize : DWORD;
driveName : string;
netResource: TNetResource;
remoteName : pointer;
wnetResult : integer;
begin
Result := false;
if mappedLetter <> '' then begin
GetMem(remoteName, MAX_PATH+1);
try
driveName := mappedLetter[1] + ':';
wnetResult := GetDriveType(PChar(driveName + '\'));
if wnetResult = DRIVE_REMOTE then begin
bufferSize := MAX_PATH;
wnetResult := WNetGetConnection(PChar(driveName), remoteName, bufferSize);
if wnetResult = ERROR_MORE_DATA then begin
FreeMem(remoteName);
GetMem(remoteName, bufferSize);
wnetResult := WNetGetConnection(PChar(driveName), remoteName, bufferSize);
end;
Result := (wnetResult = NO_ERROR) and (AnsiSameText(networkResource, Trim(PChar(remoteName))));
if (not Result) and (wnetResult = NO_ERROR) then
WNetCancelConnection2(PChar(driveName), 0, true);
end;
finally FreeMem(remoteName); end;
end;
if not Result then begin
FillChar(netResource, SizeOf (netResource), 0);
netResource.dwScope := RESOURCE_GLOBALNET;
netResource.dwType := RESOURCETYPE_DISK;
netResource.dwDisplayType := RESOURCEDISPLAYTYPE_SHARE;
netResource.dwUsage := RESOURCEUSAGE_CONNECTABLE;
if mappedLetter <> '' then
netResource.lpLocalName := PChar(driveName);
netResource.lpRemoteName := PChar(networkResource);
Result := (WNetAddConnection2(netResource, PChar(password), PChar(username), 0) = NO_ERROR);
end;
end;
begin
ConnectNetworkResource(
'\\FooBar\C$',
'L',
'ESA\LAstat',
'FooBarPwrd');
end.
lg. Astat
Lanthan Astat 06810110811210410503210511511603209711003210010110 9032084097103
03211611111604403209711003210010110903210010510103 2108101116122
11610103209010110510810103206711110010103210511003 2068101108112
10410503210310111509910411410510109810111003211910 5114100046
|
|
Zitat
|