12

Sometimes during the same Windows (Vista) session i have to connect to the same (samba) file server in a workgroup (no domain) as another user. It seems Windows has cached the current connection with user info. To force a new authentification i run a batch script:

@echo off
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y
net use * /delete /y 

But this sometime works and sometimes doesn't and force me to close the Windows session.

Is there a way to completely disconnect from actual shares to login as a new user.

Update

I have no program open, no drive letter connected and "net use" empty but still the IPC$ share open on the samba server (smbstatus).

Now adding

net use \\server\IPC$

and again

net use * /delete /y

And "net use" complains about open files or searches in folders with \server\IPC$ (message in spanish).

I think Vista is still holding the share for searching and indexing.

Update 2

I think i get this now: i stopped "Windows Search" service and after running the batch i get asked again for credentials.

3
  • Except now you get no indexing. Adding a netbios alias is a much cleaner solution.
    – djhowell
    Nov 13, 2009 at 17:00
  • On Windows 7 indexing is optional on a per-drive and even per-directory tree basis, I'm sure there must be similar settings for Vista.
    – kmarsh
    Nov 13, 2009 at 18:11
  • Also note that cases where you've done something like open a file on that share can leave an application with a directory open, which will also prevent the share from completely going away. Dec 18, 2012 at 14:42

2 Answers 2

5

Right-clicking on the drive in My Computer and saying disconnect is the most reliable way that I've found. Problems usually arise when you have a file on one of the shares held open by some process.

However, rather than disconnect when you need to access the shares as another user why don't you add a netbios alias to samba so you can use the shares with 2 different users simultaneously?

For example, if your server was named "servername" you could add this line in /etc/samba/smb.conf:

netbios aliases = altservername

Restart samba and you can then connect to \\altservername\share with a new user and windows won't care. Connecting to the IP address would probably work too but this has always seemed easier to me.

4

You can stop the "Workstation" service. This handles all SMB shares so restarting it will flush these connections.

  1. As an Administrative user, open the Services panel (Start, type services.msc and press Enter).
  2. Search for Workstation in the list on the right.
  3. Right-click Workstation, and click Restart. Wait for the progress bar to go through.
1
  • This is what I have to do on every WIn 10 device that I need to disconnect from SMB shares. net use is pmuch worthless in that regard. Really is a hassle for scripts... Jun 25, 2020 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .