Visio hangs when invoked via Task Scheduler. Anyone know why? Anyone? Bueller?

Started by pnguin34, May 16, 2012, 04:54:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pnguin34

Here's the setup:

I have a VBS script that does the following:
Dim appVisio
Dim visFile

set appVisio = CreateObject("Visio.Application")
appVisio.Visible = True
set visFile = appVisio.Documents.Open("D:\dashboard\BuildStatus.vsd")
visFile.ExecuteLine("ThisDocument.TheBigButton")
visFile.ExecuteLine("ThisDocument.SaveToWebPages")
VisFile.Save
visFile.Close
appVisio.Quit

The macro "TheBigButton" updates data in the Visio drawing from a SQL Server on localhost, and then creates shapes on pages based on the data. This works great when I launch the VBS from a Windows Explorer, and I don't get any dialogs or prompts. This is Visio 2007 SP2 on Windows Server 2008.

But when I use Task Scheduler to run it, it just hangs. I've set Visio to allow all macros to run. But I don't think it's my macro because even if I comment out the ExecuteLine and Save lines in the VBS script, it still hangs. In Task Manager, I'm not seeing any CPU time so I think Visio is getting stuck early. But I can't figure out why. Any thoughts as to the cause, or how to figure it out?

Thanks for your time.

pnguin34

It's definitely not the macro as I substituted a very simple Visio file with no macros and only a couple of shapes on a single page. Trying to open that Visio file through my VBS script produced the same results: Visio seems to be hung. I can see it in Windows Task Manager sitting doing nothing.

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

pnguin34

I can start Visio myself when logged into the server. I can also see that a Visio.EXE process has started from Task Scheduler by watching the Task Manager window. Right after the task is launched via Task Scheduler, the process shows up. The Visio process starts up with my username as the process owner. But then things just appear to stop. Even if my VBS looks like this:
Dim appVisio
Dim visFile

set appVisio = CreateObject("Visio.InvisibleApp")
set visFile = appVisio.Documents.Open("D:\dashboard\BuildStatus - Simple.vsd")
visFile.Close
appVisio.Quit

it's getting stuck. I found out there's another way to create the VBA object with InvisibleApp, as just shown. I thought maybe Visio was prompting for something (what though I have no idea), and that maybe by specifying InvisibleApp any dialogs would be skipped. But I get the same behavior. Visio starts but does not quit, and my VBS script never finishes either. And in Task Manager, the CPU time stays at 00:00:00 which tells me that it is getting stuck early. I truly believe that Visio is prompting for something, I can't see it, and that's where it stays until I kill it.

Jumpy

Hello there.

I guess it's not enough to allow all macros. You must allow other applications to interact with Visio. Don't know the name of that option, as I currently have no Visio.

If that still doesn't work, maybe I can suggest a workarround:
You could start Visio itself from the Task-Scheduler. You can start it with the command line parameter to open the drawing you want. In that drawing you place your code to start with the OnDocument_Opened-Event.
So you need no VB-Script at all. The code is stored in the / with the drawing.


Paul Herber

What I mean is, can your script start Visio 100%? Turn off the invisible bit for now.
If it can then do a few simple things, create a document, save it locally, then do it using the same path as your document. Then do the same with invisible set.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

pnguin34

My script runs reliably when I launch it manually in the Windows GUI. When Task Scheduler runs my script, I can tell that Visio starts because I can see the process in Task Manager, but nothing appears on the screen, with either Visio.InvisibleApp or Visio.Application in my script.

I tried the idea of the event handler when the document opens, but you can't quit Visio from within that handler, so then I have Visio running and my script can't tell if the macro finished successfully or not. I'm also unsure now if the next time the task runs if I get a new Visio or not, I think I do. Maybe I can run a killVisio script later to clean up.

Thank you for the suggestions. I'm still trying stuff to get this to work. My instincts are telling me that if anything needs user input due to a dialog box, if run from Task Scheduler, my script will just sit there waiting forever. If only I could see what Visio wants. Note: I'm trying to get WinDbg onto the server but corporate rules are currently preventing me from doing that. Then I might be able to see where the threads are at and figure it out that way. Until then, I welcome any other suggestions.

pnguin34

I've been able to determine that the problem occurs in the appVisio.Documents.Open line. But all I've got to work with is an error message from Visio that says "An exception occurred."


pnguin34

Visio isn't hanging. But when the Open command fails, my script was exiting and not closing Visio down. If I put in a 'On Error Resume Next' I can get Visio to accept the Quit command. But I still don't know why it doesn't like the Open command. I've tried OpenEx also but that doesn't help me. I only get this as a response from Visio:
Err.Number: -2032463768
Err.Source: Microsoft Visio
Err.Description:

An exception occurred.

I changed the Visio file that's being opened to one that is a single page with a few shapes on it. Very simple and still it gives me the error I cannot understand.

Jumpy

Maybe you can find information here. It seems, that serverside automation has some problems:

http://support.microsoft.com/kb/257757/EN-US

------------

To kill Visio, you could start a small service that checks, if the Last-modified date of your files has changed and than kills Visio. Or you kill Visio with the taskscheduler itself after for example an hour (if you know, that the makro usally  runs only for some minutes).

Paul Herber

Have you considered trying this using PowerShell rather than VB?

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

pnguin34

After reading the MS article on why I should not be attempting to automate a Visio macro on a server (thanks for the link Jumpy!), I'm going to see if the Open XML SDK works with Visio (although on first glance it doesn't appear to).

I've also attempted using PowerShell (thank you Paul for that suggestion) but with the same unfortunate results. First I tried running my .bat file via PowerShell. No luck. Then I thought I would try scripting in PowerShell to launch the Visio file and run the macro. However, I can't seem to find a method through PowerShell to invoke the macro. Sample PS scripts for Excel just don't work when the same syntax is applied to Visio. (Method invocation failed because [System.__ComObject#{000d0700-0000-0000-c000-000000000046}] doesn't contain a method named 'run'.)

It's too bad this isn't as easy as it should be. But I guess Visio just can't handle being without a logged in user context.

aledlund

The current openXML sdk does not support Visio; it only supports the three current openXML products (word, excel, and powerpoint).
al