Question

I'm coding a program to monitor a remote directory, and I use the windows API: WNetAddConnection. I use it to map remote directory to Z: by use a specified user/password.

After I put this program to the working environment, someone use explorer location "\192.168.X.X\somedir" to login the same directory I monitored, and it makes my program cannot connect to this directory, so I have to ask this people not to do this thing, but I cannot force them not to.

So I want to know if there is a way to disconnect all the other connection, or provent them do this thing, do anyone knows how?

By the way, I'm not a expert in windows, I don't know the detail of windows network (or what this bug really means), can anyone tell me where is the documentation for windows network?

Was it helpful?

Solution

Ugly option:

You could parse the output of "net use" and then disconnect the connections you don't like using "net use /d"

(WNetCancelConnection2 seems to be the API that net use /d uses)

OTHER TIPS

WNetCancelConnection2

But it's not the friendliest thing to do to people.

Not sure about the API but net session /delete will disconnect all open session to a share.

you can do this follow the step: 1,run the order to delete all the net user and the passwd ,the order is : rundll32.exe shell32.dll,Control_RunDLL keymgr.dll 2,delete all the information of the net user in the memory use the order: net use * /delete /y or you can create one bat file whit the follow information:

@echo off
rundll32.exe shell32.dll,Control_RunDLL keymgr.dll
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y

net use
net use
net use

net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top