Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1571
  • Last Modified:

ASP/VBScript How to tell if a file is locked/being written to

I have a web process that someone needs to manually start (can not automate the starting of it) that needs to be kicked off once files are done being generated by another process.

Without constantly going into the directory to see if the files are done being generated is there anyway to tell if the files are locked/still being created with ASP/VBScript code?

I want to create a page on the website that tells them the status of the files so that they can tell when it is done so they can start the process but I can not find anything that does this.

I want to be able to do this with ASP (or VBScript) so I can run the report from the website.
0
brad2575
Asked:
brad2575
  • 3
  • 3
  • 2
2 Solutions
 
HecatonchiresCommented:
Have you looked into using the pstools utilities to see if the process that creates the files is still running?  Either that, or the same suite to see if a filehandle is opened pointing at the directory.

http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx

PsFile is a command-line utility that shows a list of files on a system that are opened remotely, and it also allows you to close opened files either by name or by a file identifier.

pslist shows process information - 'pslist exp' would show all processes that start with exp.  It's trivial to write a vbscript that would execute either of these tools, but here's a helper:


' generic function to run a command and log the standard output.
' returns the exit code.
Function runCmd(cmd)
	Dim objExecObject
	Dim strText
	Set objExecObject = objShell.Exec(cmd)
 
	' wait for it to finish
	do while objExecObject.Status = 0
		WScript.Sleep 100
	loop
 
	do while not objExecObject.StdOut.AtEndOfStream
		strText = objExecObject.StdOut.ReadLine()
		Wscript.stdout.writeline(strText)
	loop
	runCmd = objExecObject.ExitCode
End Function

Open in new window

0
 
sybeCommented:
> once files are done being generated by another process.

What I would do, is to have that 'other process' indicate somewhere that it has finished. For example it could change a field in a database or write a specially named file after having done everything else.

All you have to do is check for that indication that the other process has reached its end.
0
 
brad2575Author Commented:
The problem with these is that the process is on a completely different server and environment and it is an outdated system and would not be possible to do something with the server that is generating the files.
0
Technology Partners: 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!

 
sybeCommented:
Well then.

How does a person find out that the process has finished? Looking into the directory and if nothing has changed for 2 minutes, then it is finished? You could do the same by script.

II don't think that VBScript can see if a file is locked. Anyway even with VBScript you'd have to use an object (FileSystemObject). The only way I know that and FSO can detect if a file is locked is by trying to change is - if it is locked, an error is generated. Not a very nice detection method.

0
 
brad2575Author Commented:
sybe,

Yea I know that is the issue I am running into, the only way to see if it is locked try to do something to it, if I do that and it is being used I could mess stuff up, if not then I change the file.

What I was planning on doing if I could not find a solution was to just check the time last file change/updated/created and if that minus the current date/time is more then x minutes then it should be all set.  Not the best method but the only one that would be reasonable without possibly messing with the files or everything else that could cause issues.

0
 
brad2575Author Commented:
Good ideas just either not possible or just too much of a possibility to cause issues so will just do a date check and if not changed in x number of minutes it should be set.
0
 
HecatonchiresCommented:
pstools is designed to run against a different server.  Different environment not so much - you could use an ssh script to run a ps on a unix box..  If the files are being written to your webserver (running IIS) then you can definately look to see if the filehandle is still open using psfile
0
 
HecatonchiresCommented:
Should mention that ps (process show?) is a standard unix command, and the pstools were written for windows box's to emulate that command.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now