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).
Who is Participating?
Try the following...


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

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

Open in new window

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"


strProcessName = "AcroRd32.exe"

If IsProcessRunning(strProcessName) = True Then
	MsgBox "PDF process IS running."
	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
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.