[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

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).
0
americaneldercare
Asked:
americaneldercare
1 Solution
 
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

0
 
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

0
 
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.
0

Featured Post

Independent Software Vendors: 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!

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