Script to unlock files and folder

HI Experts,

I want a VBScript/batch file that take file or folder name as input and unlock that file which is in use or locked by other user.

I know there are third party softwares that does it but i cannot install it on the production servers.
So can you please help me in getting this software.

LVL 4
anuroopkoka2005Asked:
Who is Participating?
 
anuroopkoka2005Connect With a Mentor Author Commented:
i got a solution from the internet that we can use psfile to unlock the file and it is working well..

Also using Net FIle command we can do the same but Net file does not provide u the full path of the file.

I am also attaching the script i prpared for this...
@ECHO off
cls
:start
ECHO.
ECHO Welcome to FPS Manager Script for File Shares, Printer Shares and sessions:--
ECHO.
ECHO Press: 1 - Display all the open shared files on a server and the lock-id
ECHO Press: 2 - To unlock files and Folders
ECHO Press: 3 - Display a list of computers in the current domain. 
ECHO Press: 4 - Display a list of all shares in the domain
ECHO Press: 5 - Delete a share
ECHO Press: 6 - List all sessions connected to given machine
ECHO Press: 7 - Disconnect all sessions from a given machine
ECHO Press: 8 - Display a local shares
ECHO Press: 0 - EXIT
ECHO.
set choice=0
set /p choice=Enter your choice:
if [%choice%]==[1] goto enable1
if [%choice%]==[2] goto enable2
if [%choice%]==[3] goto enable3
if [%choice%]==[4] goto enable4
if [%choice%]==[5] goto enable5
if [%choice%]==[6] goto enable6
if [%choice%]==[7] goto enable7
if [%choice%]==[8] goto enable8
if [%choice%]==[0] goto end
ECHO "%choice%" is not a valid option. Please try again...
ECHO.
goto start
 
:enable1
ECHO Ignore the machine name if you want to check for the local machine on which the script is running..
ECHO.
set /p machineid=Enter the machine name where you want to see the open files and folders:
psfile \\%machineid%
PAUSE
goto start
 
 
:enable2
set /p input=Enter the File or folder ID or PATH which you want to unlock:
psfile "%input%" -c
PAUSE
goto start
 
:enable3
NET VIEW 
PAUSE
goto start
 
 
:enable4
NET VIEW /DOMAIN 
PAUSE
goto start
 
:enable5
set /p input=Enter the Share name which you want to delete:
NET SHARE "%input%" /DELETE 
PAUSE
goto start
 
:enable6
set /p computername=Enter the Computer name for which you want list all sessions:
NET SESSION \\%ComputerName% 
PAUSE
goto start
 
:enable7
set /p computername=Enter the Computer name for which you want disconnect all sessions:
NET SESSION \\%ComputerName% /DELETE 
PAUSE
goto start
 
:enable8
net share 
PAUSE
goto start
 
 
 
:end

Open in new window

0
 
merowingerCommented:
i do not know any method unlocking a file.
Is there an option to do it with manually in OS? If so it could be possible...
0
 
anuroopkoka2005Author Commented:
Just to know how the applications like unlocker does it... and files and folder unlocker does that.

The problem with file and folder unlocker is that it writes to the registry for adding a short cut in the right-lcik menu on all files, folder and drives...
0
 
merowingerCommented:
yeah i know unlocker, what you expect is to write a script which does the same as unlocker...
I think this is very complicated. I cannot write such a script or maybe i need much time for it....
Maybe this could help you... http://www.visualbasic.happycodings.com/Files_Directories_Drives/code48.html
0
 
anuroopkoka2005Author Commented:
The above script uses PSFILE... and u can even remotely unlock the files
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.