Page 1 of 1 1
Topic Options
#93128 - 2003-10-25 05:01 PM Open FIles (Locked)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This request is for a co-worker's requirement. He has an application that sometimes cannot access a file because it is locked by another user. He wants the non-admin user to be able to determine who has the lock on the file so that the user can get the lock removed. What they do now, is to call the helpdesk to get an admin to do a NET FILE at the server to determine who has the file locked. He would like a solution that does not require admin intervention.

I poked around in WMI but could not find anything. I also looked in the UDF lib and only found one UDF that would report whether a file was locked but not by whom.

Does someone have a method for a non-admin to determine who has a lock on a file?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93129 - 2003-10-25 06:01 PM Re: Open FIles (Locked)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Les, might give this free sysinternals utility a try, we're currently using it to debug an IE6 frezzing problem ... it dumps open file handles by process etc ... not sure if it works on a file on share though ...

SysInternals Handle Utility

We kinda use it like:

F:\>handle

handle.exe pid: 2960 TASSIE\Shawn.Tassie
48: File F:\
b8: File F:\del.me

-Shawn


Top
#93130 - 2003-10-25 06:03 PM Re: Open FIles (Locked)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Never mind - this utility isn't what you want.
Top
#93131 - 2003-10-25 06:37 PM Re: Open FIles (Locked)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Dang! Thought you had something. [Frown]

Their PSFile utility is really close, but I believe needs admin rights. http://www.sysinternals.com/ntw2k/freeware/psfile.shtml

Reading that page raises my hopes.
quote:
PsFile uses the NET API, which is documented in the Platform SDK
Was really hoping for a COM method using the NET API, hence my posting to the COM forum, but may have to resort to using an external util and either encrypt the admin password {{{shudder}}} or create some sort of client/server proxy rights thingy.

They could create a server-side script running on their intranet server with a page that lets the non-admin query the file usage. Bottom line is that this is not for me but for a sysadmin at another division that I want to nudge in the right direction, but not prepared to serve ready code on a silver platter. Not sure how much time and effort they are willing to invest.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93132 - 2003-10-25 07:10 PM Re: Open FIles (Locked)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
The optional parms for username and passwrd are used to authenticate on the remote machine I guess, dont think it necessarily needs to be an admin but I am not sure ... if the user is looking at the locks on a file on a share ... then imagine they wouldn't need to provide id & pwd at all ... not sure
Top
#93133 - 2003-10-25 07:22 PM Re: Open FIles (Locked)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Was just looking at some of the "NET API"'s on MSDN and yeah it says:

Only members of the Administrators or Server Operators local group can successfully execute the NetFileEnum function.

But not all of them require it. Some say:

No special group membership is required to successfully execute the NetGetAnyDCName function.

Top
#93134 - 2003-10-26 02:42 AM Re: Open FIles (Locked)
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I have some Perl code put together that shows who has the file open using NetFileEnum and then forces it closed.

Granted that the closing of the file may require administrator rights. Would you like to try an simple EXE?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#93135 - 2003-10-26 02:57 AM Re: Open FIles (Locked)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't have all the details, only that often when the user tries to save the file, they cannot and have to hunt down an admin to first see who has the lock on it and then I believe they just go to the offending user and reboot them.

I asked Dimitri, my counterpart at the sister mill, to join this thread. He has been lurking on the board but don't think he has a user profile. We'll see if he comes out of the shadows.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93136 - 2003-10-26 07:28 AM Re: Open FIles (Locked)
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
What about something like Hyena, where you can terminate threads to a file?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#93137 - 2003-11-01 05:30 AM Re: Open FIles (Locked)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
think hoby has it there.
and yes, no special rights are needed to know the user who has lock on file.
_________________________
!

download KiXnet

Top
#93138 - 2003-11-04 04:15 PM Re: Open FIles (Locked)
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
the everyday problem that still needs a free solution.. only found this:

http://www.winnetmag.com/Article/ArticleID/24503/24503.html
_________________________
The tart is out there

Top
#93139 - 2003-11-05 11:56 PM Re: Open FIles (Locked)
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Solving half the problem !

I have transformed the VB code that masken found to KiX.

This will tell the user who has locks on the file, they can then phone the offending users, and ask them to close the file.

I have not tested the script with a domain user account, so it might not work, but used with admin rights it is very quick.

(Excel must be installed, because the script uses Excel for output !!)

code:
Dim $oFSO, $Resource
Dim $FileName, $ServerName
Dim $Row, $oXL

'Enter filename or part of filename of locked file: '
GetS $FileName

?'Enter servername: '
GetS $ServerName

? 'Checking locks for filename: ' + $FileName + ' on server: ' $ServerName

$oXL = CreateObject("Excel.Application")
$RC = $oXL.workbooks.add()

$oXL.Cells(1, 1).Value = "User"
$oXL.Cells(1, 2).Value = "Path"

$oFSO = GetObject("WinNT://" + $ServerName + "/LanmanServer")

$Row = 2
If VarTypeName($oFSO) = 'Object'
For Each $Resource In $oFSO.Resources
If $Resource.User <> "" And Right($Resource.User,1) <> "$"
If InStr($Resource.Path, $FileName)
$oXL.Cells($Row, 1).Value = $Resource.User
$oXL.Cells($Row, 2).Value = $Resource.Path
$Row = $Row + 1
EndIf
EndIf
Next
EndIf

$oXL.Cells($Row + 1, 1).Value = 'Filename: ' + $FileName
$oXL.Cells($Row + 1, 2).Value = 'Number of file locks: ' + CStr($Row - 2)
$RC = $oXL.Cells.EntireColumn.Autofit
$oXL.Visible = True

$oXL = 0

-Erik

Top
#93140 - 2003-11-06 05:10 PM Re: Open FIles (Locked)
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I took Erik's code and incorporated Kixforms as the display mechanism, however I would like to add a function that allows the lock to be removed without having to shell out and use NET FILE. I've come across some very promising leads in ADSI, however none have panned out to actually remove the lock. I was looking at IADsFileServiceOperations and Sessions/Resources related to that, and when they didn't pan out I checked all the various IADs interfaces and still came up empty. Anyone know where to point me on this assuming it is even possible to do as I wish.

Here's my version of Erik's code, and unfortunately I don't see an easy way to allow non-admins to view the locks as when a regular user runs it on our network, it just comes up with no results.
code:
BREAK ON
DIM $oFSO, $Resource

$FORM = CREATEOBJECT("KIXTART.FORM")
$FORM.SIZE = 600,400
$FORM.CENTER
$FORM.CAPTION = "Find File Locks"
$lblSERVER = $FORM.Label("Server:")
$lblSERVER.SIZE = 60,15
$lblSERVER.LOCATION = 10,12
$txtSERVER = $FORM.TextBox
$txtSERVER.SIZE = 70,19
$txtSERVER.LOCATION = 80,10
$lblFILE = $FORM.Label("File Name:")
$lblFILE.SIZE = 60,15
$lblFILE.LOCATION = 10,42
$txtFILE = $FORM.TextBox
$txtFILE.SIZE = 210,19
$txtFILE.LOCATION = 80,40
$cmdFIND = $FORM.CommandButton("Find")
$cmdFIND.SIZE = 60,19
$cmdFIND.LOCATION = 160,10
$cmdFIND.ONCLICK = "cmdFIND_CLICK()"
$cmdFIND.DEFAULT = 1
$cmdCANCEL = $FORM.CommandButton("Cancel")
$cmdCANCEL.SIZE = 60,19
$cmdCANCEL.LOCATION = 230,10
$cmdCANCEL.ONCLICK = "$$FORM = 'NOTHING'"
$cmdCANCEL.CANCEL = 1
$lblSTATUS = $FORM.Label("Status: Waiting for input")
$lblSTATUS.SIZE = 200,15
$lblSTATUS.LOCATION = 10,75
$lsvLIST = $FORM.ListView
$lsvLIST.SIZE = 575,260
$lsvLIST.LOCATION = 10,105
$ = $lsvLIST.COLUMNS.ADD("User",100,0)
$ = $lsvLIST.COLUMNS.ADD("File",471,0)
$txtSERVER.SETFOCUS
$FORM.SHOW


WHILE $FORM.VISIBLE
$ = EXECUTE($FORM.DOEVENTS)
LOOP


FUNCTION cmdFIND_CLICK()
$ = $lsvLIST.ITEMS.CLEAR
$lblSTATUS.TEXT = "Status: Checking locks for filename " + $txtFILE.TEXT + " on server " + $txtSERVER.TEXT
$oFSO = GetObject("WinNT://" + $txtSERVER.TEXT + "/LanmanServer")
$CNT = 0
IF VARTYPENAME($oFSO) = "Object"
FOR EACH $Resource IN $oFSO.Resources
IF $Resource.User <> "" AND RIGHT($Resource.User,1) <> "$"
IF INSTR($Resource.Path, $txtFILE.TEXT)
$CNT = $CNT + 1
$ITEM = $lsvLIST.ITEMS.ADD($Resource.User)
$ITEM.SUBITEMS(0).TEXT = $Resource.User
$ITEM.SUBITEMS(1).TEXT = $Resource.Path
ENDIF
ENDIF
NEXT
ENDIF
$lblSTATUS.TEXT = $txtFILE.TEXT + " : Number of file locks: " + $CNT
ENDFUNCTION

-Ben
http://www.rgcweb.org/kix

[ 06. November 2003, 17:12: Message edited by: Ben Dulaney ]

Top
#93141 - 2003-11-06 08:34 PM Re: Open FIles (Locked)
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I took a shot at using NET FILE to remove the lock on files, however it is way more coding then I anticipated. One of the problems is that NET FILE does not support remote functions, so I have to schedule a job to run on the server that I want to close the file on (through AT), and then I get the file off the server (the server is our main file server so it can output the display to itself which works around any network issues with the scheduler). However, the main impediment to this is that the NET FILE command only gives 40 characters worth of data for the files so it makes matching the line from the file with the one in the listview a real pain [Mad] For now I'll leave it without the functionality that would really make it useful.

-Ben
http://www.rgcweb.org/kix

[ 06. November 2003, 21:26: Message edited by: Ben Dulaney ]

Top
#93142 - 2003-11-10 10:52 AM Re: Open FIles (Locked)
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
good old "have to disable shares before backup" problem too heh [Wink]
_________________________
The tart is out there

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2630 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.126 seconds in which 0.086 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org