473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to call a VB6 application from Windows Service Application

DH
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

Jul 21 '05 #1
3 2975
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
Jul 21 '05 #2
DH
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
Jul 21 '05 #3
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" <an*******@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
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

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
0
by: bs | last post by:
Hi, I am currently having a problem calling a web service that is secured using a digital certificate. I set up a Windows application to make a call to the service and it works fine. However...
2
by: elora_c | last post by:
I'm making a call to a webservice from my ASP.NET page. The web application has anonymous access turned off and Integrated Windows auth turned on. The web.config has <identity impersonate=true>. ...
3
by: DH | last post by:
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...
0
by: Griff | last post by:
Overview When the first call to our Web Service causes an exception, the Web Service caches that user's credentials for its life time. Details We have a Web Service which uses Windows...
3
by: BLUE | last post by:
I've to call 2 web method from time to time so that the web service will do cleanup and sync jobs on a database. These methods can be called once every X days where X >= Y for the sync method...
3
by: =?Utf-8?B?Y2hlbmRyaWNrcw==?= | last post by:
I have a C# winforms application that makes periodic web service calls in background thread to my web service server. These calls work fine almost all the time but on rare occassions the web...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
5
by: Stefano Tonello | last post by:
Hi all, I need to call windows' "open with" dialog from my C# windows form application. After the user selects application, control must return to me (I have to launch directly the process). I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.