1

I call WNetAddConnection2 many times without WNetCancelConnection2, I just check its return value. This works in windows server 2003, only create one connection, but in windows server 2008, it created too many connection. What's the problem?

EDIT - code as per comment:

TCHAR szLocalName[32] = _T("t:"), szRemoteName[MAX_PATH] = _T("\\\\ws2008_1\\sample_share");

// Assign our values to the NETRESOURCE structure. 
nr.dwType = RESOURCETYPE_ANY; 
nr.lpLocalName = szLocalName; 
nr.lpRemoteName = szRemoteName; 
nr.lpProvider = NULL; 

// Call the WNetAddConnection2 function to assign 
// a drive letter to the share. 
dwRetVal = WNetAddConnection2(&nr, 0, 0, FALSE);

Output is:

mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:8956
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:7284
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:8592
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:4196
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7708
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7028
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:3988
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:3680
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:6364
remote name is <\\ws2008_1\sample_share_2> and errCode is: 85 PID:7764
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:8764
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:4692
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:4996
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:5300
mount <x:> to <\\ws2008_1\sample_share_2> with :0 PID:6028

Note: the process was created by CreateProcessAsUser, the user name is the same. From the log message, it works sometimes, is it logon session related?

Thanks

Dma

15
  • More infomation: I call this function in different processes. Will it affect the result? And another strange thing: I can't see driver name in "Computer".
    – Da Ma
    Aug 15, 2011 at 5:14
  • the point is more: what are the parameters you call it with ? how often ? what is the reason you call it often ? are processes for example in different sessions/terminal server connections ? any reason why you don't call WNetCancelConnection2 ?
    – Yahia
    Aug 15, 2011 at 5:17
  • At some time point, there are more than 30 process call this function at the same PC with the same parameters. It's a distributed system that use shared folders to exchange result.
    – Da Ma
    Aug 15, 2011 at 5:23
  • the processes on the same pc reside on the same desktop or are they running with different users ?
    – Yahia
    Aug 15, 2011 at 5:34
  • They are the same users.
    – Da Ma
    Aug 15, 2011 at 6:25

1 Answer 1

1

The error messages is NOT session related... it says ERROR_ALREADY_ASSIGNED (see http://msdn.microsoft.com/en-us/library/ms681382%28v=vs.85%29.aspx).

This means the method you use to mount has been called more than one time in that session (different parts of your application, multiple instances of the application in same session, restarted application in same session...).

Your method to do so is flawed - you need to:

There are other points to make sure... but they depend on the answers to the following questions:

  • Does the application run within the same session multiple times ?
  • Does the application try the mount in different parts of the application ?
  • Is this a TerminalServer environment ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.