Solved

Checking for Locked Files in Specific Folder

Posted on 2010-08-17
11
505 Views
Last Modified: 2012-05-10
Hi EE,

Is it possible to write a Batch Script that will check the file lock status for the contents of a whole folder and in turn spit out only the locked files and by which program to a txt file?

Thank you for your help in advance

Ross
0
Comment
Question by:Ross Turner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Accepted Solution

by:
Dave_LaSalle earned 500 total points
ID: 33455597
0
 
LVL 26

Expert Comment

by:pony10us
ID: 33455652
You need to be on the server with administrative rights to run this.
@echo off
REM **************************
REM * change to the proper drive
REM * In this example I use D:
REM **************************

D:

REM ***************************
REM * change to the desire directory
REM ***************************

cd \test

REM ***************************
REM * create list of locks as locks.txt
REM ***************************

net file > locks.txt

REM ****************************
REM * This creates a text file in the 
REM * current directory
REM ****************************

Open in new window

0
 
LVL 7

Author Comment

by:Ross Turner
ID: 33456084
Thank you for such quick replies,

i will test the handle concept a little more Dave_LaSalle and come back on that one



pony10us I tested the script but it always returns

"There are no entries in the list"

any ideas ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:pony10us
ID: 33456147
My code will give you all locks on the specified drive. You may want to look into Dave's suggestion as well.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 33456164
Ross,

The code if for a server and you have to be on the server to run it otherwise you get the results that you recieved.
0
 
LVL 12
ID: 33456423
NET FILE won't spit out full paths if the paths are too long.  In fact, it will only show the information for ALL files opened through a SHARE on the server not just the files in the current directory so changing directory to the one in question won't help.

However you can just type a bit of the file name and path if you like into some find commands if that will help you you will see who is locking the file.

BUT you cannot see the process locking the file.  I believe the only way to do that you need to use the PS tools from Microsoft/SysInternals



NET FILE | FIND /I "desktop.ini"
0
 
LVL 26

Expert Comment

by:pony10us
ID: 33456534
Thank you QCubed. I was just reviewing what my code did and noticed the same thing. It shortens the path so it is hard to decipher the proper location.

ID         Path                                    User name            # Locks
-------------------------------------------------------------------------------
1807446    D:\apps\...\teller1102\teller.lk        ABURT                 1

However it does give the process ID as well as the user that has the file locked.

In any case, for the author's purpose it is not the best tool so I agree that either handle or PS should be looked at.
0
 
LVL 12
ID: 33457138
that is actually the FILE ID, the process ID would likely not be above 10,000..  Also since NET FILE Shows the files locks only a on the share, and what user  is locking them, there si no way to show the process ID of another machine.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 33457179
Wow, vacation sure took a toll on my brain.   Too much time with the granddaughter I guess.  :)

Of course you are correct QCubed.
0
 
LVL 7

Author Comment

by:Ross Turner
ID: 33457323
Hey Guys,

I have to say the handle process from Dave_LaSalle seems to be just the ticket, but thank you for all your input.

I seem to be on a exponential learning curve this week and have now solved some problems plaguing our servers, so thank you so much

:)
0
 
LVL 12
ID: 33460086
NP!  Glad to be of any help!  (That is dual responce to both Pony10us and RossTurner ^^)  have a good evening gents!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerCli import module 2 53
78 files, need to delete row 2 in every file 3 34
IF statement on a PowerShell Script 2 32
Puppet Help -- if else exec trigger file 4 33
A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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