[dba-VB] Running an app from a service

DWUTKA at marlow.com DWUTKA at marlow.com
Thu Aug 18 10:37:03 CDT 2005

It's not visible because NT Services do not interact with the desktop.  You
can set a service to be interactive though.  Haven't done an NT service in
.Net, but when the service is registered with the OS, just go into the
service properties, and the Log On tab, and put a checkbox in 'Allow service
to interact with desktop'.

Just a note, if you are using a specific account to run the service as
(which is required if you are going to try and hit network resources that
require authentication), this option will not be available, since it is only
for running as the Local System account.


-----Original Message-----
From: John W. Colby [mailto:jwcolby at colbyconsulting.com]
Sent: Thursday, August 18, 2005 10:32 AM
To: 'Access Developers discussion and problem solving'; VBA
Subject: [dba-VB] Running an app from a service

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")

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)

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

Contribute your unused CPU cycles to a good cause:

dba-VB mailing list
dba-VB at databaseadvisors.com

More information about the dba-VB mailing list