vbscript if PDF is open

I know this is a bit of an odd issue - but I need to test if a PDF file is in use/open.  I have a backend workflow system designed to grab/process PDF files, however these same PDF's are visible to the users and we have an issue now and then where the file is still 'opened' by the user and thus cannot be grabbed by the workflow.

I have checked with the Workflow vendor and they don't have any way built in to test for this and they don't consider being unable to grab the file an error (if the system generated an error I could work with it).
americaneldercareAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prashanthdCommented:
Try the following...


file_path="C:\test.pdf"

On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Err.Clear
objfso.MoveFile file_path, file_path

If Err.number=0 Then
    WScript.Echo "file not open"
Else
    WScript.Echo "file open"
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sungenwangCommented:
This checks for the Adobe Reader process. If the process is running, a PDF file is currently opened.

The Adobe process name on my laptop is AcroRd32.exe. It might be different on yours. You'll need to open Windows Task Manager (right click on Windows Tray and select Task Manager) to check. It probably starts with something like "Acro"

sew


strProcessName = "AcroRd32.exe"

If IsProcessRunning(strProcessName) = True Then
	MsgBox "PDF process IS running."
Else
	MsgBox "PDF process IS NOT running."
End If


Function IsProcessRunning(strProcessName)
	IsProcessRunning = False
	Set objService = GetObject ("winmgmts:")

	For Each objProcess in objService.InstancesOf ("Win32_Process")
		If objProcess.Name = strProcessName Then 
			IsProcessRunning = True
			Exit For
		End If
	Next
End Function

Open in new window

americaneldercareAuthor Commented:
sungenwang - the workflow is a server based system, the file is being opened by non-local user.
prashanthd - that looks promising and I will be testing it shortly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.