copying network files - session remains opened?

I need to copy a file from one machine to another (both are remote)

To do it I use WNetAddConnection2 to authenticate over the remote machines and to map network drives to the administrative shares \\machine\C$ on both machines. Then I just use FileCopy(Ex). After all I close both connections with WNetCancelConnection2.

The problem is that in Computer Management->System Tools->Shared Folders->Sessions after each routine described above a new session is being opened and it stays there until I close it manually. In a while machine refuses to copy the files, because to many sessions are opened.

All the machines are under Windows 2k3. The runite is implemented as the ISAPI Extension.

How can I force the session to close, or maybe you could propose any other workarounds?

Thanks
Anton

[813 byte] By [Anton_] at [2007-12-23]
# 1

You're using WNetAddConnection2 to create a connection from the client to the server share for every file, even though they're the same?

Are you using WNetCancelConnection2 when you're done with that connection?

PeterRitchie at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...
# 2
What do you mean with your first question? Per each routine I copy only one file, and each time I use WNetAddConnection2 and WNetCancelConnection2.

The answer to the second question is Yes.

Thank you for your attention

Anton_ at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...
# 3
Here is what I am thinking... After copying the file and calling the WNetCancelConnection2 in the Computer Management->Shared Folders-> Sessions I can see that the session has 1 opened file. It lasts for a few seconds, then the open files number goes to 0.

I think that WNetCancelConnection2 can not close the connection because there is an opened file. How can I force the Connection Session to close the file?

I looked through NetUseDel API call, but I cant make it working.....

NET_API_STATUS NetUseDel(
LMSTR UncServerName,
LMSTR UseName,
DWORD ForceCond
);

What should I putsen as the input parameters?
MSDN says that UncServerName must be NULL. Is it true? What should I put as the second parameter?

Thanks
Anton

Anton_ at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...
# 4
Ok.. It is solved now.... I had to put to the WNetCancelConnection the mapped drive path, but not the remote share UNC.

Thank you for your attention.
Anton

P.S. Why did you move the topic from Visual C++ forum?

Anton_ at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...
# 5
Can you please post the code here. I have the same problem of connecting to network shares in VC++
gaag_baan at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...
# 6
Hi gaag_baan,

Unfortunately I cant find the code on my machine right now. We have it in out source safe company repository, but I even don't have an account in it. I will try to extract it tomorrow.

But please could you be more specific - what is your problem? you can't unmount network share can you? Maybe it will be faster if you will post your code and I could give a suggestion how to fix it.

Thanks
Anton

Anton_ at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows SDK...

Software Development for Windows Vista

Site Classified