How to call a VB6 application from Windows Service Application

G

Guest

I hope this is a right place to post my question

I'm working on a Windows service application with VB.net. The purpose is to let the service application as a monitor to periodically check a launching flag file. If the flag was found the service will trigger to run a finance calculating program (VMPE4SRVAPP.exe, a VB 6.0/Access application but without windows interface). I added a Process and two Timers on the Service to do checking and launching jobs (Process1.Start to call VMPE4SRVAPP.exe) . Please see the following code

Imports System.ServiceProces

Public Class MyNewServic
Inherits System.ServiceProcess.ServiceBas

Protected Overrides Sub OnStart(ByVal args() As String

EventLog1.WriteEntry("In OnStart"
Timer2.Enabled = Tru

End Su

Protected Overrides Sub OnStop(

EventLog1.WriteEntry("In OnStop."

End Su

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapse

Timer1.Enabled = Fals

Dim myProcess As New Proces

Process1.StartInfo.FileName = "C:\VMPE4SRVAPP\VMPE4SRVAPP.exe
Process1.StartInfo.Arguments = "vm3retail
Process1.StartInfo.WorkingDirectory = "C:\VMPE4SRVAPP
Process1.StartInfo.RedirectStandardOutput = Fals
Process1.StartInfo.WindowStyle = ProcessWindowStyle.Minimize
Process1.Start(

Timer2.Enabled = Tru

End Su

Private Sub Timer2_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer2.Elapse

If Len(Dir("C:\temp\LaunchingFlag.ok")) > 0 The
Timer2.Enabled = Fals
Kill("C:\temp\LauchingFlag.ok"
Timer1.Enabled = Tru
End I

End Su

End Clas

I installed the service. When I started it, I could see (from windows explorer) a MDB file was generated and its size indicated that data was loaded. I also saw VMPE4SRVAPP.exe was displayed on Processes tab of Windows Task Manager. However the process stayed on the tab forever. When I tried to open the MDB file, I got "Access denied... It is already being in use". When I tried to copy the MDB I got "Sharing violation".
I can only access the MDDB file after I re-boot my PC
What's wrong with my code? Or is there a better way to call my VB 6.0 Calc application in Windows Service? Can I use Shell in a Service instead of Process (If I can how to coding them)

Thanks for your help
 
M

MW

DH,

You can check if the process has completed using the HasExited property.

It is possible that something is preventing your VB6 process from
completing? Are there any message boxes in the application that might be
holding up your VB6 app? Since you cannot access the UI you may not know
about it. Possibly a simple way to find out is to execute the exe externally
with the same arguments and see if the application terminates in the end.

Also since this process is starting from a service, I would set the
CreateNoWindow = True and the WindowStyle to hidden, because there is no
user input to the UI of the process.

You can shell execute if you set ProcessStartInfo.UseShellExecute to True.
However if you do that you will not be able to redirect output or error
streams in your service application.

HTH
Wazir
 
G

Guest

Hi Wazir

Good start point! I will try to run my VB6.0 exe externally to see if any MsgBox hold it to end the job. You mentioned "CreateNoWindow"/"WindowStyle". Are they properties of Process (I will check them out later afternoon)

DH
 
M

MW

DH,

If you have any message boxes (or anything else that may require user input)
then the process will not complete inside the service. It will be a good
idea to remove them if you can (or allowed to). Also when you test the app
externally make sure the arguments are the same as you gave in the windows
service.

The properties belong to the Process.StartInfo object

Dim oProcessStartInfo as new ProcessStartInfo()
Dim oProcess as Process

With oProcessStartInfo
.FileName = [Filename]
.Arguments = [Arguments]
.UseShellExecute = False
.CreateNoWindow = True
End With
oProcess = Process.Start(oProcessStartInfo)

Regards,
Wazir


DH said:
Hi Wazir.

Good start point! I will try to run my VB6.0 exe externally to see if any
MsgBox hold it to end the job. You mentioned "CreateNoWindow"/"WindowStyle".
Are they properties of Process (I will check them out later afternoon)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top