从服务运行VB EXE [英] Running a VB EXE from a Service

查看:60
本文介绍了从服务运行VB EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用进程".从.Net服务调用VB EXE.

EXE有一个UI,但我没有使用它,而是使用......
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

调用是通过参数进行的,EXE所做的全部工作就是为我创建一个SQL表.我不想重复代码,因此对现有应用程序进行了调用.

从Windows应用程序调用时,EXE会调用并正常运行,但是从服务中调用时,EXE将失败,该服务不会超过Process.Start()

  Dim  objProcess  As   Process()
       objProcess.StartInfo.UseShellExecute = 错误
       objProcess.StartInfo.CreateNoWindow = 错误
       objProcess.StartInfo.FileName = " 
       objProcess.StartInfo.Arguments = cString
       objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
       objProcess.Start()


有任何想法吗?

我不想重复代码,因此将对现有应用程序进行调用."
进程之间是高度隔离的.除非这种隔离是您的特定目标之一,否则您不应出于任何其他原因尝试使用单独的流程.没有明显的原因,您会遇到这种方法的许多问题.

您是否仍需要将应用程序分开并关心代码的重用?将代码重构为在单独的库程序集中具有应作为Windows Service和交互式应用程序的一部分运行的部分,并在两个项目中均引用该程序集.在Windows Service的过程中运行此代码以创建SQL表.

您可能需要在单独的线程中运行此代码,但对自己做一个很大的帮忙:甚至不要通过Process.Start玩一个单独的进程的想法 . 1)做sp没有一个单一的原因; 2)这样做会给您带来种种麻烦.您有一个简单而稳定的解决方案来解决问题.

通常,程序集,程序集可执行模块,线程和进程都是不同的实体.您需要有关其含义和预期用途的任何解释吗?正确使用它们而不是滥用它们符合您的利益.

—SA


只需添加到SAKryukov所说的内容...

无论如何,您都不需要隐藏窗口.服务在用户看不到的单独桌面下运行.您的服务启动的任何过程对用户都是不可见的.

听起来好像您的服务应该创建SQL表,或者更好的是,应该在安装时而不是运行时创建它们.


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

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?

解决方案

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


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.


这篇关于从服务运行VB EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆