Tôi đang gặp sự cố khi cố gắng gọi WNetAddConnection2 cho máy mà tôi đã có phiên. Điều này được mong đợi, vì bạn chỉ có thể kết nối với tài nguyên mạng với chỉ một bộ thông tin đăng nhập. Những gì tôi đang cố gắng làm là bắt tình trạng này và tự động gọi WNetCancelConnection2 để ngắt kết nối tất cả các kết nối hiện có và sau đó thử lại cuộc gọi WNetAddConnection2. Khi tôi chạy mã dưới đây tôi nhận được các thông điệp ghi:WNetAddConnection2 và lỗi 1219 - Tự động ngắt kết nối?
DEBUG - WNetAddConnection2 returned 1219
DEBUG - Multiple credentials detected, disconnecting all current sessions
DEBUG - WNetCancelConnection2 returned 0
DEBUG - WNetAddConnection2 returned 1219
Nếu tôi đặt dwFlags để CONNECT_UPDATE_PROFILE trong WNetCancelConnection tôi nhận được các thông điệp ghi:
DEBUG - WNetAddConnection2 returned 1219
DEBUG - Multiple credentials detected, disconnecting all current sessions
DEBUG - WNetCancelConnection2 returned 2250
DEBUG - WNetAddConnection2 returned 1219
Đây là nguồn của tôi, tất cả help is appreciated!
networkName = @"\\192.168.1.1";
var netResource = new NetResource()
{
Scope = ResourceScope.GlobalNetwork,
ResourceType = ResourceType.Disk,
DisplayType = ResourceDisplaytype.Share,
RemoteName = networkName
};
int result = WNetAddConnection2(netResource, credentials.Password, credentials.UserName, 0);
log.Debug("WNetAddConnection2 returned " + result);
if (result == 1219)
{
log.Debug("Multiple credentials detected, disconnecting all current sessions");
result = WNetCancelConnection2(networkName, 0, true);
log.Debug("WNetCancelConnection2 returned " + result);
result = WNetAddConnection2(netResource, credentials.Password, credentials.UserName, 0);
log.Debug("WNetAddConnection2 returned " + result);
}