views:

481

answers:

4

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?

+1  A: 
WNetCancelConnection2

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

Windows programmer
we are developing a program only used in our factory, and the users are workers...
linjunhalida
A: 

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

+1  A: 

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)

thijs
A: 

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,delet 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

wflishh