Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using "Process." to call a VB EXE from a .Net Service.

The EXE has a UI but I am not using it and use.........
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

The call is made with parameters and all the EXE is doing is creating a SQL table for me. I do not want to duplicate code, hence the call being made to an existing app.

The EXE calls and works fine when called from a Windows App, but fails when called from a service, the Service doesnt get past the Process.Start()

VB
Dim objProcess As New Process()
       objProcess.StartInfo.UseShellExecute = False
       objProcess.StartInfo.CreateNoWindow = False
       objProcess.StartInfo.FileName = "FileName"
       objProcess.StartInfo.Arguments = cString
       objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
       objProcess.Start()

Any ideas?
Posted
Updated 6-Jul-11 18:26pm
v2

This is really, really bad justification of what you're trying to do:

"I do not want to duplicate code, hence the call being made to an existing app."
Processes are highly isolated from each other. Unless such isolation is one of your specific goals, you should not try to work with a separate process by any other reason. You will have to many problems with this approach for no apparent reason.

Do you need the application to be separate anyway and care about code re-use? Re-factor your code to have the part which should be run as a part of Windows Service and interactive application in a separate library assembly and reference this assembly in both projects. Run this code in the process of your Windows Service to create your SQL tables.

It's likely that you will need to run this code in a separate thread, but do yourself a big favor: don't even play with the idea of running a separate process via Process.Start. 1) There is no a single reason for doing sp; 2) doing so would get you in all kind of trouble. You have a simple and stable solution for you problem.

In general: assembly, assembly executable module, thread and process are all different entities. Do you need any explanations on their meaning and intended use? It's in your interest to use them properly, not to abuse them.

—SA
 
Share this answer
 
Comments
[no name] 7-Jul-11 0:53am    
Very true. my +5.
Sergey Alexandrovich Kryukov 7-Jul-11 1:20am    
Thank you.
--SA
Just to add to what SAKryukov said...

You don't need to Hide the window anyway. Services run under a seperate desktop that the user cannot see. Any process that your service launches will be invisible to the user.

It sounds as though your service should be creating the SQL tables, or, better yet, they should be created at install time, not runtime.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900