在服务中执行应用程序 [英] Executing an application inside a Service

查看:78
本文介绍了在服务中执行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


i已经写了一个服务,现在我想在服务中执行另一个应用程序(对于

例如; calc.exe)。 ......我将如何表演?...


i尝试使用这个....


/ ***** *********执行进程代码从这里开始************** /

System.Diagnostics.Process proc = new System.Diagnostics。 Process();

proc.EnableRaisingEvents = false;

proc.StartInfo.FileName =" calc";

proc.Start() ;

/ **************执行流程代码在此结束************** /


上面的代码没有用.......还有什么是另一种选择还是我的

方法错了?...

问候,

CCChakkaradeep

解决方案

Chakkaradeep,


运行时发生了什么?从一个

服务中运行另一个程序并不是世界上最好的主意,特别是如果它有一个UI。如果它是b $ b有一个用户界面,那么你必须让服务与桌面互动,即使这样,你也不能保证会有一个桌面会话(那里

如果没有人登录就没有了。)


你想做什么?

-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam .guard.caspershouse.com


" Chakkaradeep" <章********** @ discussions.microsoft.com>在消息中写道

新闻:D4 ********************************** @ microsof t.com ...

大家好,
我已经写了一个服务,现在我想执行另一个应用程序(例如:
; calc.exe)在服务中....我将如何表演?...

我尝试使用它....

/ ******** ******执行进程代码从这里开始************** /
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName =" calc";
proc.Start();
/ ************* *执行流程代码在这里结束************** /

以上代码无效.......其他替代方案是什么或者是我的方法错了吗?...

问候,
CCChakkaradeep






我的服务是一个多线程服务器,它监听

特定端口的连接....如果有任何传入连接ons来了,服务器接受它并且

通过接收来自Socket的

信息来启动一个带有从远程端获得的参数的应用....这就是我想要的做...我已经开发了一个

多线程服务器作为服务运行,通过发回

回复客户端工作正常......但是我无法执行申请....


那么我的下一步是什么?...我是服务的新手...


with问候,

CCChakkaradeep


Nicholas Paldino [.NET / C#MVP]"写道:

Chakkaradeep,

运行时发生了什么?从一个
服务中运行另一个程序并不是世界上最好的主意,特别是如果它有一个UI。如果它有一个UI,那么你必须让服务与桌面交互,即使这样,你也不能保证会有一个桌面会话(那里是
)如果没有人登录就没有。)

你想做什么?

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

Chakkaradeep <章********** @ discussions.microsoft.com>在消息中写道
新闻:D4 ********************************** @ microsof t.com。 ..

大家好,
我已经写了一个服务,现在我想在服务中执行另一个应用程序(例如; calc.exe)。 ......我将如何表演?...

我试过用这个....

/ ************ **执行进程代码从这里开始************** /
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName =" calc";
proc.Start();
/ **************执行进程代码在这里结束************** /

以上代码无法正常工作.......其他选择是什么或者是我的
接近错误?...

问候,
CCChakkaradeep




< blockquote>正如我之前告诉过你的,服务不应该考虑存在一个

的交互式destop,而且,它们不应该产生proc具有UI的元素

(他,他们根本不应该生成进程)。

默认情况下,服务在沙盒桌面环境中运行,

在交互式桌面环境中运行服务(启用

与桌面交互)在服务属性中)只应被视为

用于调试目的。


Willy。


Chakkaradeep ; <章********** @ discussions.microsoft.com>在留言中写道

新闻:7D ********************************** @ microsof t.com ...



我的服务是一个多线程服务器,用于侦听特定端口的连接....如果有任何传入连接来,服务器接受它

启动一个应用程序,通过接收来自远程端的参数来接收来自Socket的信息....这就是我想要做的...我已经开发了一个作为服务运行的多线程服务器,通过向客户发送
回复来工作正常......但是我无法执行应用程序...... 。

那么我的下一步是什么?...我是服务的新手...

问候,
CCChakkaradeep
< Nicholas Paldino [.NET / C#MVP]"写道:

Chakkaradeep,

运行时发生了什么?在
服务中运行另一个程序并不是世界上最好的主意,特别是如果它有UI。如果
它有一个UI,那么你必须让服务与桌面交互,即使这样,你也不能保证会有一个桌面会话
(如果没有人登录,则
是没有。)

你想做什么?

-
- Nicholas Paldino [ .NET / C#MVP]
- mv*@spam.guard.caspershouse.com

Chakkaradeep <章********** @ discussions.microsoft.com>在消息中写道
新闻:D4 ********************************** @ microsof t.com。 ..

>大家好,
>
>我已经写了一个服务,现在我想在服务中执行另一个应用程序(对于
>例如; calc.exe)....我将如何执行它?...
>
>我试过用这个....
>
> / **************执行流程代码从这里开始************** /
> System.Diagnostics.Process proc = new System.Diagnostics.Process();
> proc.EnableRaisingEvents = false;
> proc.StartInfo.FileName =" calc";
> proc.Start();
> / **************执行流程代码在这里结束************** /
>
>上面的代码不起作用.......另一种选择是什么?
>我的
>接近错误?...
>
>问候,
> C.C.Chakkaradeep




Hi all,

i have written a Service,now i want to execute another application (for
eg;calc.exe) in the service....how will i perform it??...

i tried using this....

/**************Executing a Process code starts here**************/
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="calc";
proc.Start();
/**************Executing a Process code ends here**************/

the above code is not working.......what is the other alternative or is my
approach wrong??...

with regards,
C.C.Chakkaradeep

解决方案

Chakkaradeep,

What''s happening when you run it? Running another program from inside a
service isn''t the best idea in the world, especially if it has a UI. If it
has a UI, then you have to let the service interact with the desktop, and
even then, you can''t guarantee that there will be a desktop session (there
is none if no one is logged in).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...

Hi all,

i have written a Service,now i want to execute another application (for
eg;calc.exe) in the service....how will i perform it??...

i tried using this....

/**************Executing a Process code starts here**************/
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="calc";
proc.Start();
/**************Executing a Process code ends here**************/

the above code is not working.......what is the other alternative or is my
approach wrong??...

with regards,
C.C.Chakkaradeep



Hi,

My Service is a Multithreaded Server which listens for connections at a
particular port....if any incoming connections come,the server accepts it and
starts an application with the parameter got from remote end by receiving the
informations from Socket....this is what i want to do...i have developed a
Multithreaded Server runnning as service,it is working fine by sending back
replies to clients....but am not able to execute an application....

so what is my next step??...am a newbie to Services...

with regards,
C.C.Chakkaradeep

"Nicholas Paldino [.NET/C# MVP]" wrote:

Chakkaradeep,

What''s happening when you run it? Running another program from inside a
service isn''t the best idea in the world, especially if it has a UI. If it
has a UI, then you have to let the service interact with the desktop, and
even then, you can''t guarantee that there will be a desktop session (there
is none if no one is logged in).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...

Hi all,

i have written a Service,now i want to execute another application (for
eg;calc.exe) in the service....how will i perform it??...

i tried using this....

/**************Executing a Process code starts here**************/
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="calc";
proc.Start();
/**************Executing a Process code ends here**************/

the above code is not working.......what is the other alternative or is my
approach wrong??...

with regards,
C.C.Chakkaradeep




As I told you before, services should not consider the presence of an
interactive destop, also, they should not spawn processes that have a UI
(he, they should not spawn processes at all).
By default services run in the context of a sandboxed desktop environment,
running a service in the context of the interactive desktop (enabling
"interact with desktop" in the Service properties) should ONLY be considered
for debugging purposes.

Willy.

"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...

Hi,

My Service is a Multithreaded Server which listens for connections at a
particular port....if any incoming connections come,the server accepts it
and
starts an application with the parameter got from remote end by receiving
the
informations from Socket....this is what i want to do...i have developed a
Multithreaded Server runnning as service,it is working fine by sending
back
replies to clients....but am not able to execute an application....

so what is my next step??...am a newbie to Services...

with regards,
C.C.Chakkaradeep

"Nicholas Paldino [.NET/C# MVP]" wrote:

Chakkaradeep,

What''s happening when you run it? Running another program from
inside a
service isn''t the best idea in the world, especially if it has a UI. If
it
has a UI, then you have to let the service interact with the desktop, and
even then, you can''t guarantee that there will be a desktop session
(there
is none if no one is logged in).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:D4**********************************@microsof t.com...

> Hi all,
>
> i have written a Service,now i want to execute another application (for
> eg;calc.exe) in the service....how will i perform it??...
>
> i tried using this....
>
> /**************Executing a Process code starts here**************/
> System.Diagnostics.Process proc = new System.Diagnostics.Process();
> proc.EnableRaisingEvents=false;
> proc.StartInfo.FileName="calc";
> proc.Start();
> /**************Executing a Process code ends here**************/
>
> the above code is not working.......what is the other alternative or is
> my
> approach wrong??...
>
> with regards,
> C.C.Chakkaradeep




这篇关于在服务中执行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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