Page 1 of 1 1
Topic Options
#92600 - 2003-08-11 06:56 PM Checking to see if File Is In Use
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
I hope someone can help me...This topic may have come up before, but when I did a search I couldn't find anything...

Anyway...I would like to check to see if a particular file is in use. I CANNOT try and open the file for Read/Write access and test whether the return code is not zero.

Ideally I would like to search the list found in Computer Management (Windows 2000)..."System Tools\Shared Folders\Open Files" and look for a particular entry.

Is it possible to search this list?

Cheers guys,

Lee

Top
#92601 - 2003-08-11 07:02 PM Re: Checking to see if File Is In Use
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
How about this thread form just a couple of days ago: Determining "In-Use" File Information
_________________________
There are two types of vessels, submarines and targets.

Top
#92602 - 2003-08-11 07:04 PM Re: Checking to see if File Is In Use
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Dang, I just barely got beat to the punch.
Top
#92603 - 2003-08-12 11:02 AM Re: Checking to see if File Is In Use
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
Cheers Jens,

I am really struggling to try to manipulate CIM_DataFile.

Am I doing it correctly?

Here is my code...

code:
Dim $strFileName, $strComputer
Dim $objWMIService, $colFiles, $objFile

CLS

$strFileName = "e:\\apakds\\apak\\sas\\action.ldb"
$strComputer = "."

$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colFiles = $objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile WHERE Name = '" + $strFileName + "'")

For Each $objFile in $colFiles
? "Name: " + $objFile.Name
? "File name: " + $objFile.FileName
? "InUseCount: '" + $objFile.InUseCount + "'"
Next

If I look in Computer Management (Windows 2000)..."System Tools\Shared Folders\Open Files" I can see that this particular file has "4" locks.

However, when I run this code it returns the following...

code:
InUseCount: ''

Why doesn't it return "4". I would have expected a numerical value to be returned.

Can anyone help me?

Lee

Top
#92604 - 2003-08-12 04:23 PM Re: Checking to see if File Is In Use
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I checked into the InUseCount and it returns NULL independent of whether a file/folder is in use or not. I've ran that against my own computer and a fileserver, filtering for any file where InUseCount<>NULL and didn't get a single return. Teh MSDN documentation is pretty poor and I haven't been able to find a single script that actually uses that property, they normally just display it.

[ 12. August 2003, 16:34: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#92605 - 2003-08-12 04:41 PM Re: Checking to see if File Is In Use
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
Cheers Jens!

Thanks anyway!

Lee

Top
#92606 - 2003-08-12 09:39 PM Re: Checking to see if File Is In Use
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Lee, you may want to consider the WaitFor ActiveX component I provided a link for in the referenced thread. You may be able to achieve the results you want using it.
Top
#92607 - 2003-08-12 09:43 PM Re: Checking to see if File Is In Use
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Not sure if this helps.. But here is some code that uses this property -

http://www.scriptinternals.de/content/ref/wmi/namespaces/root_cimv2/CIM_DataFile/InUseCount.htm

If you can get around the German. [Wink]

HTH,

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

Top
#92608 - 2003-08-12 09:56 PM Re: Checking to see if File Is In Use
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I do get around the German. [Smile] It actually one of the scripts i found when investigating it this morning. Note, that it not really uses the property, it only displays it.

I do not get around the fact that InUseCount returns NULL for everything. [Smile]
_________________________
There are two types of vessels, submarines and targets.

Top
#92609 - 2003-08-12 11:14 PM Re: Checking to see if File Is In Use
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I know that this may not be ideal, but have you tried getfiletime() function. I believe it will return "" if the file is in use.

code:
if getfiletime($file) = ""
;file in use
else
;file not in use
endif

_________________________
Eric

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
1 registered (Allen) and 337 anonymous users online.
Newest Members
SERoyalty, mytar, Gabriel, Alex_Evos, Dansen
17869 Registered Users

Generated in 0.061 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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