vbscript if PDF is open

Posted on 2011-10-05
Last Modified: 2012-05-12
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).
Question by:americaneldercare
    LVL 12

    Accepted Solution

    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

    LVL 14

    Expert Comment

    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


    Author Comment

    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.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    This is an explanation of a simple data model to help parse a JSON feed
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now