Introduction:
I have a script which copies some data from the local server (Server A) to another server (Server B) through an UNC path, the share in the Server B was created for an external hard disk which is changed every day, after the external HDD is swapped the new HDD is mounted using the mountvol command, the assigned letter is the same, but as you might already know the Volume Name for each HDD is different.
The problem as I got it (step by step):
If I open Explorer in the Server B and go to the UNC path, which means in the Server A there is a session from Server B for my (User X), in the cmd I perform using another account (User Y) e.g.:
dir \\path"
and I see the files, so at this point there are 2 sessions from the same computer and different users.
Curiosity: the session for User Y will stay until in the command line you write another command, or the cmd window loses focus - instead of closing the session right after the dir command has finished.
With the curiosity above, the 2nd session for User Y can be ignored in this case, this leaves us one session in Server A for User X
I go to Server B, unmount the HDD using mountvol (Can be done in Computer Management also), swap the HDD and then I mount the new HDD.
I go back to server A, in the cmd window I perform again the DIR command with any account User X or Y, and I get:
The system cannot find the file specified.
If I go to the open explorer window and refresh the window, the files don't appear also.
- I found on the internet that after restarting the explorer process in Server B, then the shared files are visible again, i.e. deleting the sessions in Server A (all the sessions?), another trick was just to delete the session in the Server B.
Possible Solution --> I want your help here :)
Since the script (batch script) is automatic and I don't want to check if there is any hanging session from Server B in Server A, I would like to force the close of all the hanging sessions for a given share in Server A BUT I would like to do it from my script in Server B, the "net sess(ion(s))" is for local purposes.
If you have any other suggestion, by this I mean another possible solution, please let me know. Thank you.
Technical Information:
Server A: Windows Server 2008 R2 Enterprise SP1
Server B: Windows Server 2003 Enterprise SP2
Notes: Correct me if I wrong, but I think that:
Refreshing the view in the Explorer Window for an UNC path doesn't work since the Volume Name is different, unmounting and mounting it again (same HDD), makes the refresh to work normally. Is this perhaps a security functioning? or is this a bug? or am I missing something?
After running dir for an unc path and retrieving the list of files should close right away the session as there isn't any more "processing" with it.
After running the dir for an unc path, the sessions stays open, but when you click on another windows (the cmd window loses focus) the session disappears.