function Connect(MachineName, Username, Password:
string): DWORD;
var
NetResource: TNetResource;
dwResult, dwBufSize, dwFlags: DWORD;
sRemote:
string;
begin
// ADMIN$ wird von XP Home nicht unterstützt, also:
sRemote := '
\\' + MachineName + '
\IPC$';
dwFlags := 0;
ZeroMemory(@NetResource, sizeof(TNetResource));
with NetResource
do begin
dwUsage := RESOURCEUSAGE_CONNECTABLE;
// = 1
dwDisplayType := RESOURCEDISPLAYTYPE_GENERIC;
// = 0
dwType := RESOURCETYPE_ANY;
// = 0
lpLocalName :=
nil;
lpRemoteName := PChar(sRemote);
lpProvider :=
nil;
end;
Result := WNetUseConnection(Application.Handle, NetResource,
PChar(UserName), PChar(Password), dwFlags,
nil, dwBufSize, dwResult
);
end;
procedure TDemoForm.ConnectButtonClick(Sender: TObject);
var
dwResult: DWORD;
begin
// kein user/pswd bei xp home verwenden
dwResult := Connect('
DECIUS', '
', '
');
ShowMessage(SysErrorMessage(dwResult));
end;