Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Automating a GUI program with VBS from a Windows Service

Reply
 
Old 10-10-2009   #1 (permalink)
Scott Gifford


 
 

Automating a GUI program with VBS from a Windows Service

Hello,

I have a VBS script I used to automate Adobe Illustrator to do some
file format conversions. The script works fine when run from the GUI.

I would like to automate it further by running the script as a Windows
service. I have set this up using SrvAny from the Windows Resource
Kit, and the VBScript seems to run fine, but it hangs when it tries to
start up Illustrator.

I suspect that the problem is that Illustrator tries to bring up a
GUI, but it can't because the Service environment has no GUI.

Does anybody have any advice or suggestions for overcoming this?

Thanks,

-----Scott.

My System SpecsSystem Spec
Old 10-10-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Automating a GUI program with VBS from a Windows Service


"Scott Gifford" <sgifford@newsgroup> wrote in message
news:83076acc-691f-4684-b7cf-5305ec414d76@newsgroup
Quote:

> Hello,
>
> I have a VBS script I used to automate Adobe Illustrator to do some
> file format conversions. The script works fine when run from the GUI.
>
> I would like to automate it further by running the script as a Windows
> service. I have set this up using SrvAny from the Windows Resource
> Kit, and the VBScript seems to run fine, but it hangs when it tries to
> start up Illustrator.
>
> I suspect that the problem is that Illustrator tries to bring up a
> GUI, but it can't because the Service environment has no GUI.
>
> Does anybody have any advice or suggestions for overcoming this?
>
> Thanks,
>
> -----Scott.
Hard to say without seeing your script. Perhaps you have some interactive
modules.


My System SpecsSystem Spec
Old 10-10-2009   #3 (permalink)
Scott Gifford


 
 

Re: Automating a GUI program with VBS from a Windows Service

On Oct 10, 1:32*pm, "Pegasus [MVP]" <n...@newsgroup> wrote:
Quote:

> "Scott Gifford" <sgiff...@newsgroup> wrote in message
>
> news:83076acc-691f-4684-b7cf-5305ec414d76@newsgroup
>
Quote:

> > I have a VBS script I used to automate Adobe Illustrator to do some
> > file format conversions. *The script works fine when run from the GUI..
>
Quote:

> > I would like to automate it further by running the script as a Windows
> > service. *I have set this up using SrvAny from the Windows Resource
> > Kit, and the VBScript seems to run fine, but it hangs when it tries to
> > start up Illustrator.
>
Quote:

> > I suspect that the problem is that Illustrator tries to bring up a
> > GUI, but it can't because the Service environment has no GUI.
>
Quote:

> > Does anybody have any advice or suggestions for overcoming this?
>
Quote:

> > Thanks,
>
Quote:

> > -----Scott.
>
> Hard to say without seeing your script. Perhaps you have some interactive
> modules.
I have simplified my test script down to this (based on Adobe's sample
VBS code):

Set appRef = CreateObject("Illustrator.Application")
Rem Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
Rem Create a new text frame item and assign it to a variable
Set sampleText = documentRef.TextFrames.Add
Rem Set the contents and position of the TextFrame
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"
documentRef.SaveAs("C:\tmp\hello.ai")
documentRef.Close(aiDoNotSaveChanges)

Thanks for any advice!

----Scott.
My System SpecsSystem Spec
Old 10-10-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Automating a GUI program with VBS from a Windows Service


"Scott Gifford" <sgifford@newsgroup> wrote in message
news:82a6fd67-f6e8-4aa6-9edf-90a67c0428f5@newsgroup
On Oct 10, 1:32 pm, "Pegasus [MVP]" <n...@newsgroup> wrote:
Quote:

> "Scott Gifford" <sgiff...@newsgroup> wrote in message
>
> news:83076acc-691f-4684-b7cf-5305ec414d76@newsgroup
>
Quote:

> > I have a VBS script I used to automate Adobe Illustrator to do some
> > file format conversions. The script works fine when run from the GUI.
>
Quote:

> > I would like to automate it further by running the script as a Windows
> > service. I have set this up using SrvAny from the Windows Resource
> > Kit, and the VBScript seems to run fine, but it hangs when it tries to
> > start up Illustrator.
>
Quote:

> > I suspect that the problem is that Illustrator tries to bring up a
> > GUI, but it can't because the Service environment has no GUI.
>
Quote:

> > Does anybody have any advice or suggestions for overcoming this?
>
Quote:

> > Thanks,
>
Quote:

> > -----Scott.
>
> Hard to say without seeing your script. Perhaps you have some interactive
> modules.
I have simplified my test script down to this (based on Adobe's sample
VBS code):

Set appRef = CreateObject("Illustrator.Application")
Rem Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
Rem Create a new text frame item and assign it to a variable
Set sampleText = documentRef.TextFrames.Add
Rem Set the contents and position of the TextFrame
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"
documentRef.SaveAs("C:\tmp\hello.ai")
documentRef.Close(aiDoNotSaveChanges)

Thanks for any advice!

----Scott.

=================

I do not have a copy of Adobe Illustrator and am therefore unable to test
your code. Here are a few tips that might help you:
- What makes you think that the code "hangs"?
- Where exactly does it hang? How did you find out?
- What triggers execution of your code?
- Does the code below work for you?

The script runs continuously in a loop. Once every 5 seconds it checks if
the semaphore file d:\sem.txt exists. If the file does exist then the script
will do this:
- Delete the semaphore file.
- Write a date/time stamp into d:\Report.txt.
- Open the file d:\test.doc in MS Word and mark the word "Fabrikam" bold.
- Save & close the file and close MS Word.

If the script runs for you then I suggest you replace the word-specific code
with Adobe-specific code.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Do While True
If oFSO.FileExists("d:\sem.txt") Then
oFSO.DeleteFile("d:\sem.txt")
Modify
End If
WScript.Sleep 5000
Loop

Sub Modify
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open("D:\Test.doc")
Set objSelection = objWord.Selection
With objSelection
.Find.Text = "Fabrikam"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Replacement.Font.Bold = True
.Find.Execute , , , , , , , , , , 2
End With
objDoc.Save
objDoc.Close
objWord.Quit
Set objWord = Nothing
Set oReport = oFSO.OpenTextFile("d:\Report.txt", 8, True)
oReport.WriteLine Date & " " & Time
oReport.Close
End Sub


My System SpecsSystem Spec
Old 10-11-2009   #5 (permalink)
Scott Gifford


 
 

Re: Automating a GUI program with VBS from a Windows Service

On Oct 10, 4:57 pm, "Pegasus [MVP]" <n...@newsgroup> wrote:
Quote:

> "Scott Gifford" <sgiff...@newsgroup> wrote in message
[ ... ]
Quote:

> Here are a few tips that might help you:
> - What makes you think that the code "hangs"?
> - Where exactly does it hang? How did you find out?
Those are really good questions, thank you. They prompted me to
investigate further. I rewrote my test program to provide more useful
diagnostics, and this is what I see:

Log opened
Starting Illustrator
Illustrator Started, creating new document
Failed
Error number -2147352577
Error description: an Illustrator error occurred: 271 ('')
Error source: Adobe Illustrator

So, it seems Illustrator is throwing an error with code 271, and not a
lot of other information.

This is my new test program:

Set fs = CreateObject("Scripting.FileSystemObject")
Set logfile = fs.OpenTextFile("d:\log.txt", 8, True)
logfile.WriteLine("Log opened")

On Error Resume Next
RunIt()

Rem *** If we got here, there was an error
Rem *** (since the below sub exits if it succeeds)
logfile.WriteLine("Failed")
logfile.WriteLine("Error number " & Err.Number)
logfile.WriteLine("Error description: " & Err.Description)
logfile.WriteLine("Error source: " & Err.Source)
logfile.Close()
wscript.quit(2)

Sub RunIt()
logfile.WriteLine("Starting Illustrator")
Set appRef = CreateObject("Illustrator.Application")
logfile.WriteLine("Illustrator Started, creating new document")

Rem *** Create a new document and assign it to a variable
Set documentRef = appRef.Documents.Add
logfile.WriteLine("Document created, doodling")

Rem *** Draw some stuff in the document
Set sampleText = documentRef.TextFrames.Add
sampleText.Position = Array(200, 200)
sampleText.Contents = "Hello World!"
logfile.WriteLine("Done doodling, saving")

documentRef.SaveAs("d:\hello.ai")
logfile.WriteLine("Done saving, closing")

documentRef.Close(aiDoNotSaveChanges)
logfile.WriteLine("Done closing, exiting")

logfile.Close()
wscript.quit(1)
End Sub

Quote:

> - What triggers execution of your code?
It is run directly from a Windows Service, using SrvAny and
cscript.exe.
Quote:

> - Does the code below work for you?
Sorry, I don't have a copy of MS Word so I couldn't try it, hopefully
my experiments above will provide information which is useful in
answering the same questions your code would have.

Any ideas for what a next step is here?

Thanks again for your help!

----Scott.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Find which service/Program is working Vista General
How do I uninstall a program that is run as a service Vista General
Windows Vista Service Pack 1 RC Public Availability Program Vista General
Automating Windows Picture and Fax Viewer ? PowerShell
Automating Windows Media Player. PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46