473,715 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make a Windows Service start a windows program.

UJ
Is there any way for a windows service to start a windows program ? I have a
service that will need to restart a windows app if it needs to.

TIA - Jeff.
Feb 22 '06 #1
17 6438
The problem is that service isn't interactive program, thus it's loaded
before user logged on.
You need to check whether the user logged on and only after that start app.

"UJ" wrote:
Is there any way for a windows service to start a windows program ? I have a
service that will need to restart a windows app if it needs to.

TIA - Jeff.


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Feb 22 '06 #2
Just to add to my previos post than u can use WMI(System.Mana gement) and
query to the Win32_LogonSess ion to check for availability of logged user
"Michael Nemtsev" wrote:
The problem is that service isn't interactive program, thus it's loaded
before user logged on.
You need to check whether the user logged on and only after that start app.

"UJ" wrote:
Is there any way for a windows service to start a windows program ? I have a
service that will need to restart a windows app if it needs to.

TIA - Jeff.


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Feb 22 '06 #3

"UJ" <fr**@nowhere.c om> wrote in message
news:eA******** ******@TK2MSFTN GP15.phx.gbl...
| Is there any way for a windows service to start a windows program ? I have
a
| service that will need to restart a windows app if it needs to.
|
| TIA - Jeff.
|
|

No there is no (easy, secure and portable) way to do this. A windows service
runs in a sandboxed non visible desktop, a process started from a service
inherits the same UI context so it will run in the same desktop, second the
service does not run in the security context of a logon user (if any), that
means that the lauched application won't have access to an interactive user
profile, so chances are that it fails to initialize when environmant
variables or profile setting are needed.

Willy.
Feb 22 '06 #4
I recently had to create a program which could launch a .bat file
through the command prompt, you can try tinkering with this code, I
don't know if it will help you though.

System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents = false;
proc.StartInfo. FileName = fileloc;
proc.Start();
proc.WaitForExi t();

Feb 22 '06 #5


"KBuser" <Ky********@gma il.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
|I recently had to create a program which could launch a .bat file
| through the command prompt, you can try tinkering with this code, I
| don't know if it will help you though.
|
| System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
| proc.EnableRais ingEvents = false;
| proc.StartInfo. FileName = fileloc;
| proc.Start();
| proc.WaitForExi t();

The OP's question relates to a "windows" program, not a console style
program. Note that the same remark about the user profile applies when
starting a console application, an application that considers it's profile
being loaded when started will fail if started from a service.
In general, services should not start other applications, unless you have
full control of it's UI and profile context.

Willy.
Feb 22 '06 #6
> The OP's question relates to a "windows" program, not a console style
program. Note that the same remark about the user profile applies when
starting a console application, an application that considers it's profile
being loaded when started will fail if started from a service.
In general, services should not start other applications, unless you have
full control of it's UI and profile context.
What do you mean when you say:
"unless you have full control of it's UI and profile context"?


I have a similar situation where a service needs to instantiate an object
contained in a WinForms app. The service and the app are installed as a
pair; the UI is used to define the action taken by the service at
pre-defined intervals.

When constructing the assembly in Visual Studio that contains the
application/service pair, should the service and the app be in a separate
namespaces? Does it make any difference? The design goal is to keep the
service and the app a loosely coupled as possible since they run in
different security contexts.

Feb 22 '06 #7

"deko" <de**@nospam.co m> wrote in message
news:qf******** ************@co mcast.com...
|> The OP's question relates to a "windows" program, not a console style
| > program. Note that the same remark about the user profile applies when
| > starting a console application, an application that considers it's
profile
| > being loaded when started will fail if started from a service.
| > In general, services should not start other applications, unless you
have
| > full control of it's UI and profile context.
|
| What do you mean when you say:
|
| > "unless you have full control of it's UI and profile context"?
|

Well I mean that it's possible for the program that gets launched from a
Windows Service session, to load the environment and profile of an
interactive user, it's also possible to migrate the current desktop to the
(visble) interactive desktop, but this is not a trivial task and requires
some thorough understanding of the OS security system.
| I have a similar situation where a service needs to instantiate an object
| contained in a WinForms app. The service and the app are installed as a
| pair; the UI is used to define the action taken by the service at
| pre-defined intervals.
|

I suppose you mean instantiate an object through remoting right? This is not
a problem as long as the WinForms app is started from an interactive logon
session and not from the service.
| When constructing the assembly in Visual Studio that contains the
| application/service pair, should the service and the app be in a separate
| namespaces? Does it make any difference? The design goal is to keep the
| service and the app a loosely coupled as possible since they run in
| different security contexts.
|

Namespace are irrelevant here, what matters is the assemblies, both your
service and the WinForms app. should reside in a separate assembly.

Willy.
Feb 22 '06 #8
> Well I mean that it's possible for the program that gets launched from a
Windows Service session, to load the environment and profile of an
interactive user, it's also possible to migrate the current desktop to the
(visble) interactive desktop, but this is not a trivial task and requires
some thorough understanding of the OS security system.
I see.
| I have a similar situation where a service needs to instantiate an
object
| contained in a WinForms app. The service and the app are installed as a
| pair; the UI is used to define the action taken by the service at
| pre-defined intervals.
|

I suppose you mean instantiate an object through remoting right? This is
not
a problem as long as the WinForms app is started from an interactive logon
session and not from the service.


Well, that's the key question - can I do this without remoting?

The service in question will run as a Local Service since it requires full
system privaleges, but it gets launced (only) when a particular user logs
in. The UI is run in the user's security context so only that user can
adjust the parameters of the app's "projects" which are launched by the
service. The "projects" are designed to run silently in the background in a
separate thread and require no interaction with the UI (that's why I am
using a service).

However, the service needs to instantiate the Project object in the WinForms
application - this contains all the business logic. So the service needs to
pass parameters to the Project class's constructor. That's why I thought
the service and the app should be in the same assembly.

So do I really need Remoting here? I just want to instantiate the app's
Project object from the service to allow the app's "project" to run in the
service's thread and security context, while the app's UI is run in the
users's thread and security context.

Does this sound correct?

Feb 22 '06 #9

"deko" <de**@nospam.co m> wrote in message
news:fb******** ************@co mcast.com...
|> Well I mean that it's possible for the program that gets launched from a
| > Windows Service session, to load the environment and profile of an
| > interactive user, it's also possible to migrate the current desktop to
the
| > (visble) interactive desktop, but this is not a trivial task and
requires
| > some thorough understanding of the OS security system.
|
| I see.
|
| > | I have a similar situation where a service needs to instantiate an
| > object
| > | contained in a WinForms app. The service and the app are installed as
a
| > | pair; the UI is used to define the action taken by the service at
| > | pre-defined intervals.
| > |
| >
| > I suppose you mean instantiate an object through remoting right? This is
| > not
| > a problem as long as the WinForms app is started from an interactive
logon
| > session and not from the service.
|
| Well, that's the key question - can I do this without remoting?
|
| The service in question will run as a Local Service since it requires full
| system privaleges, but it gets launced (only) when a particular user logs
| in.
Services aren't lauched when users logs in, services are lauched at system
start-up, Applications that depend on interactive logon session, should
never be implemented as Windows Services, they should be normal applications
that get started at logon (search for Autorun in windows help).


The UI is run in the user's security context so only that user can
| adjust the parameters of the app's "projects" which are launched by the
| service. The "projects" are designed to run silently in the background in
a
| separate thread and require no interaction with the UI (that's why I am
| using a service).
|
| However, the service needs to instantiate the Project object in the
WinForms
| application - this contains all the business logic. So the service needs
to
| pass parameters to the Project class's constructor. That's why I thought
| the service and the app should be in the same assembly.
|

The applications should run in separate processes, so you need a 'way' to
create remote instances of classes residing in a Winforms application. One
way is through remoting (assumed both are managed apps.) and another one is
through COM interop.
One question remain, what's the use of the object instance from the UI
applications perspective? You said, the service creates an instance of class
'Project', how are you going to share the state between these two
applications?
| So do I really need Remoting here? I just want to instantiate the app's
| Project object from the service to allow the app's "project" to run in the
| service's thread and security context, while the app's UI is run in the
| users's thread and security context.
|
| Does this sound correct?
|
Willy.
Feb 22 '06 #10

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

Similar topics

2
15222
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
2
21910
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be successful. I'm now ready to start my service (I think) but the NET START command does not appear to indicate that the service is available to be run. The output for NET START is below as well. The Services list in the W2K administrator...
4
19011
by: Dao | last post by:
I have created a windows service called MyService. I followed the MSDN sample code to add the following code but it did not work. What I tried was that to start another or external program when MyService starts. I used notepad.exe as an example of a program to be called when MyService starts. I have tried both in the InitializationComponenet() then in the OnStart() Method but none of them work. Any help would be appreciated. private...
6
3042
by: Bijesh | last post by:
Hi All, I've developed a Windows Service that acts as a remoting server (.NET Remoting). The client(user) is able to connect to the server and start a program by giving the executable path of the program (in the server) along with the working directory and the arguments (parameters). This works fine if I try to start programs whose executable file is present witin the local drives of the server. If the application is in a netwok drive,...
1
3454
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
0
3937
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server - Select from two specific services - Check the status of the server
2
1327
by: Billy Cormic | last post by:
Hello, I have successfully created a windows service. I would now like the windows service to call another program and start it when the service starts. I have been unable to do this. For the windows service OnStart sub I have the following code: Protected Overrides Sub OnStart(ByVal args() As String) EventLog1.WriteEntry("In OnStart") Process.Start("Explorer.exe")
4
4180
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
1
15096
by: TJ | last post by:
I created a windows service using VS2005. I created/adjusted the install class using the designer controls. I set the user to be 'local system'. I installed the service using the VS2005 cmd console (installutil.exe). The service shows up fine in my services snap-in. I can start and stop it just fine and it works great when I start it. I can open a command window and type: net start "My Service" and net stop "My Service" and it works...
0
8817
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7966
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6641
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4472
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4734
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3171
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.