uses Windows; procedure DoLogOn(var RemotePath: String; const UserName: String; const Password: String); var NR: TNetResource; Win32Result: Integer; begin { Check local path } if (RemotePath = '') or (Copy(RemotePath,1,2) <> '\\') then begin Exit; end; RemotePath := ExcludeTrailingPathDelimiter(RemotePath); with NR do begin dwType := RESOURCETYPE_ANY; lpLocalName := nil; lpRemoteName := PChar(RemotePath); lpProvider := nil; end; Win32Result := WNetAddConnection2(NR,PChar(Password), PChar(UserName),0); if Win32Result <> NO_ERROR then begin RaiseLastOSError(Win32Result); end; end; procedure DoLogOff(const RemotePath: String); var Pathname: String; Win32Result: Integer; begin { Check local path } if (RemotePath = '') or (Copy(RemotePath,1,2) <> '\\') then begin Exit; end; Win32Result := WNetCancelConnection2(PChar(Pathname),0,False); if Win32Result <> NO_ERROR then begin RaiseLastOSError(Win32Result); end; end;
2008年7月21日
リモートPCの共有パスに接続する
Microsoftファイル共有でリモートPCの共有パスに接続するときはWNetAddConnection2を、接続を解除するときはWNetCancelConnection2を使用します。
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿