[dba-VB] Running an app from a service

John W. Colby jwcolby at colbyconsulting.com
Thu Aug 18 10:32:27 CDT 2005


I have created a service using VB.Net.  The service can be registered, once
registered I can start it etc.  It runs, with a timer tick writing a log to
application.log so I can see that the timer tick is happening.  Once I got
that working I went looking for how to run an external application from the
service.  The code I found looks like:

        Dim p As System.Diagnostics.Process
        p = System.Diagnostics.Process.Start("notepad.exe", "sample.txt")
        p.WaitForExit()

A couple of things.  Notepad is running, it can bee seen as a process in
Task Manager, but it is not visible, and it has not created sample.txt
AFAICT.  I found other code (in C# unfortunately) that looks something like:

        Dim p As System.Diagnostics.Process
        Dim psi As System.Diagnostics.ProcessStartInfo
        psi = System.Diagnostics.ProcessStartInfo
        psi.FileName = "notepad.exe"
        psi.Arguments = "sample.txt"
        psi.WorkingDirectory = "x:\Luminex"
        psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized
        p = System.Diagnostics.Process.Start(psi)
        p.WaitForExit()

PSI appears to be a structure for loading properties that P will use.  

Even when done this way, the notepad is not visible.  Furthermore, in either
case the code does not wait... Or maybe the timer spawns a thread and will
fire again spawning another thread.  In other words, next timer tick I get
another instance of Notepad.  However... If I place a line of code that
writes to the log file before and after the call to the sub that opens
notebook, the line before the call to open the notepad does log, the line
after does not log.

So, I do not understand all that I know about this stuff.  If anyone has any
ideas how to make the process visible I would appreciate it.  I also do need
the code not run again until the app shuts down.  I think I can just shut
off the timer so I can handle it that way if the timer will fire again even
if the p.WaitFor() is in place.

Any comments?  Has anyone done this?

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/





More information about the dba-VB mailing list