Page 1 of 2 12>
Topic Options
#158630 - 2006-03-09 07:45 PM How to check if a file is in use
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Can someone give me direction on how to create a script that checks if a file is in use? Thanks
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#158631 - 2006-03-09 07:48 PM Re: How to check if a file is in use
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
check out EnumProcess()
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#158632 - 2006-03-09 08:03 PM Re: How to check if a file is in use
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Benny, it looks like this UDF will check for a running process and kill it if needed. Is there a way to check if a file is in use?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#158633 - 2006-03-09 08:08 PM Re: How to check if a file is in use
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
if the file in question is a .exe it is a process
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#158634 - 2006-03-09 08:40 PM Re: How to check if a file is in use
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
The files I'm trying to check are various types of CAD data object files.

.dbf, .prj, .xml, .sbx, .sbn, .shp, .shx

I need to check if any of these files are in use on the local computer before I run a script that overwrites them. Any suggestions on how I can do this?

I may also be able to run an EnumProcess on the application that would be using these files. I don't have that information yet, so I'm starting with checking the "used" files first.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#158635 - 2006-03-09 08:46 PM Re: How to check if a file is in use
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Good luck. I asked the same question too but my friends let me down. You can do it with an older version of KiX but not the latest.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158636 - 2006-03-09 08:48 PM Re: How to check if a file is in use
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why do you need to check if they are in use? just flag them for overwrite on boot instead.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158637 - 2006-03-09 08:48 PM Re: How to check if a file is in use
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
if that is the case check out Inuse.exe.
"InUse is a command-line tool that performs on-the-fly replacement of files currently in use by the operating system. You must be a member of the Administrators group to use this tool."
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#158638 - 2006-03-09 08:49 PM Re: How to check if a file is in use
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The latest KiX has it built-in.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158639 - 2006-03-09 08:57 PM Re: How to check if a file is in use
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Can you elaborate on the "flag for overwrite on boot" suggestion? Thanks for the input.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#158640 - 2006-03-09 09:17 PM Re: How to check if a file is in use
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
There is a UDF to do this.
UpdateFileOnReboot()- Schedules a file to be replaced on reboot

Or you can put a script to replace the files in the runonce key in the registry.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#158641 - 2006-03-09 09:34 PM Re: How to check if a file is in use
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I just found this... it's comes with XP...
OpenFiles.exe

For it to check local files you first have to enable it by:
Code:
 openfiles /local on  


Then Reboot.

Once you restart then just issue the following command:
Code:
 openfiles /query 



This is my output:
Quote:


Files Opened Locally:
---------------------

ID Process Name Open File (Path\executable)
===== ==================== ==================================================
12 ati2evxx.exe C:\WINDOWS\system32
12 userinit.exe C:\Documents and Settings\Administrator
96 userinit.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 explorer.exe C:\Documents and Settings\Administrator
60 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
68 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
96 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
108 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
112 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
156 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
320 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
344 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
504 explorer.exe C:\Documents and Settings\Administrator\Desktop
512 explorer.exe C:\Documents and Settings\All Users\Desktop
516 explorer.exe C:\..\Application Data\Microsoft\CD Burning
596 explorer.exe C:\..\Microsoft\Internet Explorer\Quick Launch
668 explorer.exe C:\Documents and Settings\Administrator\Start Menu
728 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
752 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
772 explorer.exe C:\..\History\History.IE5\index.dat
780 explorer.exe C:\..\Content.IE5\index.dat
796 explorer.exe C:\..\Administrator\Cookies\index.dat
900 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
920 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
924 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
1032 explorer.exe C:\Documents and Settings\Administrator\PrintHood
1040 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
1088 explorer.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
1216 explorer.exe C:\Documents and Settings\All Users\Start Menu
80 CLI.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
228 CLI.exe C:\..\v1.1.4322\CONFIG\security.config.cch
240 CLI.exe C:\..\v1.1.4322\CONFIG\enterprisesec.config.cch
248 CLI.exe C:\..\v1.1.4322\security.config.cch
260 CLI.exe C:\..\cli.exe.c88dbd71.ini.inuse
364 CLI.exe C:\Program Files\ATI Technologies\ATI.ACE
444 CLI.exe C:\..6595b64144ccf1df_1.0.2600.2180_x-ww_522f9f82
884 CLI.exe C:\..\LOCALS~1\Temp\Perflib_Perfdata_774.dat
1368 CLI.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 msnmsgr.exe C:\Documents and Settings\Administrator
64 msnmsgr.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
68 msnmsgr.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
160 msnmsgr.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
424 msnmsgr.exe C:\Program Files\MSN Messenger\msnmsgr.exe
432 msnmsgr.exe C:\Program Files\MSN Messenger\msnmsgr.exe
440 msnmsgr.exe C:\Program Files\MSN Messenger\msnmsgr.exe
448 msnmsgr.exe C:\Program Files\MSN Messenger\msnmsgr.exe
632 msnmsgr.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
1148 msnmsgr.exe C:\..\Microsoft\SystemCertificates\My
1236 msnmsgr.exe C:\..\Content.IE5\index.dat
1256 msnmsgr.exe C:\..\Administrator\Cookies\index.dat
1264 msnmsgr.exe C:\..\History\History.IE5\index.dat
1292 msnmsgr.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
1360 msnmsgr.exe C:\..\Microsoft\Network\Connections\Pbk
12 Web2pop.exe C:\Documents and Settings\Administrator
80 Web2pop.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 msmsgs.exe C:\Documents and Settings\Administrator
16 msmsgs.exe C:\..6595b64144ccf1df_1.0.2600.2180_x-ww_522f9f82
28 msmsgs.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
68 msmsgs.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
96 msmsgs.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
376 msmsgs.exe C:\Program Files\Messenger\msmsgs.exe
384 msmsgs.exe C:\Program Files\Messenger\msmsgs.exe
392 msmsgs.exe C:\Program Files\Messenger\msmsgs.exe
12 reader_sl.exe C:\Documents and Settings\Administrator
60 reader_sl.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 SafeCfg.exe C:\..\NETGEAR\NETGEAR ProSafe VPN Client
64 SafeCfg.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 qbupdate.exe C:\..\Common Files\Intuit\QuickBooks\QBUpdate
68 qbupdate.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
92 qbupdate.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
468 qbupdate.exe C:\..\Content.IE5\index.dat
484 qbupdate.exe C:\..\Administrator\Cookies\index.dat
492 qbupdate.exe C:\..\History\History.IE5\index.dat
520 qbupdate.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
588 qbupdate.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
700 qbupdate.exe C:\..\Microsoft\Network\Connections\Pbk
12 SyncToy.exe C:\Program Files\Microsoft\SyncToy
80 SyncToy.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
228 SyncToy.exe C:\..\v1.1.4322\CONFIG\security.config.cch
240 SyncToy.exe C:\..\v1.1.4322\CONFIG\enterprisesec.config.cch
248 SyncToy.exe C:\..\v1.1.4322\security.config.cch
620 SyncToy.exe C:\..\Microsoft\SystemCertificates\My
656 SyncToy.exe C:\..\SyncToy.exe.7d71c9a.ini.inuse
660 SyncToy.exe C:\..6595b64144ccf1df_1.0.2600.2180_x-ww_522f9f82
676 SyncToy.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
712 SyncToy.exe C:\..\LOCALS~1\Temp\Perflib_Perfdata_70.dat
1232 SyncToy.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
84 OUTLOOK.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
292 OUTLOOK.EXE C:\..\Microsoft\Outlook\outcmd.dat
380 OUTLOOK.EXE C:\My Documents\Email\outlook.pst
568 OUTLOOK.EXE C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\spambayes1.log
572 OUTLOOK.EXE C:\PROGRA~1\MICROS~2\Office\MSOUTL9.OLB
600 OUTLOOK.EXE C:\Program Files\Microsoft Office\Office\MSO9.DLL
652 OUTLOOK.EXE C:\..\Email\SpamBayes\default_bayes_database.db
656 OUTLOOK.EXE C:\..\Email\SpamBayes\default_message_database.db
660 OUTLOOK.EXE C:\Program Files\Common Files\System\Mapi\1033\NT
688 OUTLOOK.EXE C:\My Documents\Email\outlook.pst
752 OUTLOOK.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
64 MAPISP32.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
324 MAPISP32.EXE C:\Program Files\Common Files\System\Mapi\1033\NT
348 MAPISP32.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
364 MAPISP32.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
372 MAPISP32.EXE C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
456 MAPISP32.EXE C:\..\Microsoft\Outlook\MSIN5300.RHC
480 MAPISP32.EXE C:\..\Microsoft\Outlook\MSIN2849.RHC
544 MAPISP32.EXE C:\My Documents\Email\outlook.pst
12 devldr32.exe C:\Documents and Settings\Administrator
60 devldr32.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 cmd.exe C:\Documents and Settings\Administrator
96 cmd.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9
12 openfiles.exe C:\Documents and Settings\Administrator
1924 openfiles.exe C:\..6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9


Files Opened Remotely via local share points:
---------------------------------------------
INFO: No shared open files found.




Top
#158642 - 2006-03-09 09:43 PM Re: How to check if a file is in use
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
OPENFILES /parameter [arguments]

Description:
Enables an administrator to list or disconnect files and folders
that have been opened on a system.

Parameter List:
/Disconnect Disconnects one or more open files.

/Query Displays files opened locally or from shared
folders.

/Local Enables / Disables the display of local open files.

/? Displays this help message.

Examples:
OPENFILES /Disconnect /?
OPENFILES /Query /?
OPENFILES /Local /?


As for the replacement KiXtart 4.52 Beta 2 supports this. The UDF by Jens does not properly support it.
 

Changes in 4.52 Beta 2:

CompareFileTimes has been enhanced so it can operate on open files.
RD further enhanced such that it continues deleting files & folders, even if an error occurs.
Fixed the handling of F10, F11, F12, etc keys by SendKeys.
Added a '/p' (Postpone) option to MOVE and DEL to enable you to postpone the actions until the next reboot. This can be useful to replace files that are normally in use.

Top
#158643 - 2006-03-09 09:57 PM Re: How to check if a file is in use
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Wsing WSHPipe I was able to check and see if my PST file was open.

Code:
 
break on



$output=wshpipe('openfiles /query',1)
for each $line in $output
if instr($line,"pst")
? $line
endif
next

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
Exit($oExec.ExitCode)
EndFunction


Top
#158644 - 2006-03-09 10:08 PM Re: How to check if a file is in use
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I hate making UDFs that are dependent on external EXEs, but this works too...

Code:
 
break on
 
if isfileopen("outlook.pst")
"File is Open"
else
"File is not Open"
endif
 
 

function isfileopen($file)
dim $output, $line
$output=wshpipe('openfiles /query',1)
for each $line in $output
if right($line,len($file))=$file
$isfileopen=1
endif
next
endfunction
 

Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split(Join(Split($Output,CHR(13)),''),CHR(10))
Exit($oExec.ExitCode)
EndFunction


Top
#158645 - 2006-03-10 01:21 PM Re: How to check if a file is in use
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mart, yes, there is a udf but like les said before you, kixtart already supports it.
thus the udf is partly obsolete.

also, checking if file is in use is the simplest to do with simple move.
if move fails, it's in use, right?
_________________________
!

download KiXnet

Top
#158646 - 2006-03-10 01:37 PM Re: How to check if a file is in use
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

if move fails, it's in use, right?



If the failure reason (@ERROR) is 32 or 33 then it's a reasonable assumption.

That's not a check if the file is in use though. A check would be non-intrusive.

Top
#158647 - 2006-03-10 01:49 PM Re: How to check if a file is in use
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
another simple test is to try open the file for writing.

richie, not sure if one can really "check" it.
is there some db that OS keeps and a coder can query about inuse files?
_________________________
!

download KiXnet

Top
#158648 - 2006-03-10 04:54 PM Re: How to check if a file is in use
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Logic suggests that there must be a table in the kernel somewhere - whether it is exposed as a scriptable API or not is another question
Top
#158649 - 2006-03-10 08:14 PM Re: How to check if a file is in use
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
I doubt your logic.
mine does not follow it
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


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

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.069 seconds in which 0.028 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