var NetResource: TNetResource; Result: cardinal; // ... NetResource.dwType := RESOURCETYPE_DISK; NetResource.lpLocalName := nil; NetResource.lpRemoteName := '\\192.168.0.100\dir'; NetResource.lpProvider := nil; Result := WNetAddConnection2(NetResource, 'password', 'username', 0); if Result = NO_ERROR then // ... // 值得注意的是:若是返回錯誤值是1219(ERROR_SESSION_CREDENTIAL_CONFLICT),代表這個網絡路徑已經鏈接了,能夠直接使用 或者 用winexec執行命令:net use \\ip /user:用戶名 密碼 而後直接 \\ip地址\ipc$\文件夾名稱