?
Solved

Script to unlock files and folder

Posted on 2009-04-21
5
Medium Priority
?
3,610 Views
Last Modified: 2012-05-06
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.

0
Comment
Question by:anuroopkoka2005
  • 3
  • 2
5 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 24194307
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
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24194338
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
 
LVL 31

Expert Comment

by:merowinger
ID: 24194422
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
 
LVL 4

Accepted Solution

by:
anuroopkoka2005 earned 0 total points
ID: 24214604
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
 
LVL 4

Author Comment

by:anuroopkoka2005
ID: 24214636
The above script uses PSFILE... and u can even remotely unlock the files
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question