Remove shared drive (using VBScript)
Q. Anytime I plug in my flash drive, Windows creates a share (eg. F$) that is accessible to people over the network. I can't permanently un-share that drive, but how would I speed up the process for removing it every time?
A. Yes, it is true that this share is accessible to people over the network, however, it is only accessible for anyone with admin rights and the person has to know that you have an F:\ drive plugged in in order to access it. In any case, this is how you would do that:
Using notepad (or my favourite - Notepad++) create a file on your desktop (eg. stop_share.vbs). Copy paste the contents below to that file:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = 'F$'")
For Each objShare in colShares
objShare.Delete
Next
Run that script any time you plug in your drive.
If you want to stop a share other than F$, just replace it in the code above. (It has to be the name of the share, not the actual folder or drive).