Hello,
I hope this question isn't too fundamental. I have a feeling it is. I'm
trying to start a winform app from a windows service written in C#. I
created a class and used it from a windowsforms application and all was
well. But when I try to use the class in the OnStart method of a windows
service, the process I'm trying to start runs but the window never shows up.
Like I said, this may be fundamentally impossible/illogical to do but here's
the basic code I'm using:
public class AppServer
{
public void StartService()
{
string path;
string app;
ProcessStartInf o psi;
string[] settings =
System.Configur ation.Configura tionSettings.Ap pSettings.GetVa lues("app");
for (int i = 0; i <= settings.GetUpp erBound(0); i++)
{
path = settings[i].Substring(0, settings[i].LastIndexOf("\ \"));
app = settings[i].Substring(sett ings[i].LastIndexOf("\ \") + 1);
Directory.SetCu rrentDirectory( path);
psi = new ProcessStartInf o(app);
psi.CreateNoWin dow = false;
psi.WindowStyle = ProcessWindowSt yle.Normal;
psi.WorkingDire ctory = path;
Process.Start(p si);
}
}
}
Any comments much appreciated.
Thanks
Steve 5 4927
Firstly, check that the service is set to allow interaction with the
desktop. You can right click the service in the SCM and check it that
way.
Secondly, since the service is probably loading under the LocalSystem
account, it may not have the necessary priveleges to run the app. You
might try having the service start up as a different user.
Hope this gives you some ideas.
Steve,
You can do it, but I would recommend against it. You would have to go
to the properties for the service and check "allow service to interact with
the desktop". However, I strongly recommend against this. If you need to
communicate to a service, then have a separate application which uses a
technology like remoting to get information from it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Steve Long" <St**********@N oSpam.com> wrote in message
news:O$******** ********@tk2msf tngp13.phx.gbl. .. Hello, I hope this question isn't too fundamental. I have a feeling it is. I'm trying to start a winform app from a windows service written in C#. I created a class and used it from a windowsforms application and all was well. But when I try to use the class in the OnStart method of a windows service, the process I'm trying to start runs but the window never shows up. Like I said, this may be fundamentally impossible/illogical to do but here's the basic code I'm using:
public class AppServer {
public void StartService() { string path; string app; ProcessStartInf o psi;
string[] settings = System.Configur ation.Configura tionSettings.Ap pSettings.GetVa lues("app"); for (int i = 0; i <= settings.GetUpp erBound(0); i++) { path = settings[i].Substring(0, settings[i].LastIndexOf("\ \")); app = settings[i].Substring(sett ings[i].LastIndexOf("\ \") + 1); Directory.SetCu rrentDirectory( path); psi = new ProcessStartInf o(app); psi.CreateNoWin dow = false; psi.WindowStyle = ProcessWindowSt yle.Normal; psi.WorkingDire ctory = path; Process.Start(p si); } } }
Any comments much appreciated.
Thanks Steve
"Steve Long" <St**********@N oSpam.com> wrote in message
news:O$******** ********@tk2msf tngp13.phx.gbl. .. Hello, I hope this question isn't too fundamental. I have a feeling it is. I'm trying to start a winform app from a windows service written in C#. I created a class and used it from a windowsforms application and all was well. But when I try to use the class in the OnStart method of a windows service, the process I'm trying to start runs but the window never shows up. Like I said, this may be fundamentally impossible/illogical to do but here's the basic code I'm using:
public class AppServer {
public void StartService() { string path; string app; ProcessStartInf o psi;
string[] settings = System.Configur ation.Configura tionSettings.Ap pSettings.GetVa lues("app"); for (int i = 0; i <= settings.GetUpp erBound(0); i++) { path = settings[i].Substring(0, settings[i].LastIndexOf("\ \")); app = settings[i].Substring(sett ings[i].LastIndexOf("\ \") + 1); Directory.SetCu rrentDirectory( path); psi = new ProcessStartInf o(app); psi.CreateNoWin dow = false; psi.WindowStyle = ProcessWindowSt yle.Normal; psi.WorkingDire ctory = path; Process.Start(p si); } } }
Any comments much appreciated.
Thanks Steve
You shouldn't launch interactive processes from Windows Services, they are
designed to run even when there is no interactive session available.
The reason is simple, each service runs in an invisible secured desktop
environment (called a Winstation), programs launched from this share the
same desktop environment, so their UI is invisible to the user.
Note that you can flip the "Enable service to interact with desktop" service
attribute, but this should only be considered as a debugging aid .
Willy.
Very good feedback everybody. You might be right that it would be a bad idea
since the primary reason for me doing this is so that the service can launch
a desktop app without the server having to be logged into by someone. The
app in question, is by design, a windowed app and therefore can not really
run as a service. It does however, serve up some intensive data and it takes
a several seconds to load the app, which is why it must be running all the
time. Can't really add the load up time to the time it takes to perform the
spatial queries. Others communicate with this application via a .aspx page
that I set up which in turn communicates with the desktop app via .NET
remoting.
So, let's say I check the option to allow the service to interact with the
desktop, allowing this app to be started up without actually logging into
the server. What are the pitfalls with this course of action?
Steve
"Steve Long" <St**********@N oSpam.com> wrote in message
news:O$******** ********@tk2msf tngp13.phx.gbl. .. Hello, I hope this question isn't too fundamental. I have a feeling it is. I'm trying to start a winform app from a windows service written in C#. I created a class and used it from a windowsforms application and all was well. But when I try to use the class in the OnStart method of a windows service, the process I'm trying to start runs but the window never shows
up. Like I said, this may be fundamentally impossible/illogical to do but
here's the basic code I'm using:
public class AppServer {
public void StartService() { string path; string app; ProcessStartInf o psi;
string[] settings = System.Configur ation.Configura tionSettings.Ap pSettings.GetVa lues("app"); for (int i = 0; i <= settings.GetUpp erBound(0); i++) { path = settings[i].Substring(0, settings[i].LastIndexOf("\ \")); app = settings[i].Substring(sett ings[i].LastIndexOf("\ \") + 1); Directory.SetCu rrentDirectory( path); psi = new ProcessStartInf o(app); psi.CreateNoWin dow = false; psi.WindowStyle = ProcessWindowSt yle.Normal; psi.WorkingDire ctory = path; Process.Start(p si); } } }
Any comments much appreciated.
Thanks Steve
"Steve Long" <St**********@N oSpam.com> wrote in message
news:Oq******** ******@TK2MSFTN GP12.phx.gbl... Very good feedback everybody. You might be right that it would be a bad idea since the primary reason for me doing this is so that the service can launch a desktop app without the server having to be logged into by someone. The app in question, is by design, a windowed app and therefore can not really run as a service. It does however, serve up some intensive data and it takes a several seconds to load the app, which is why it must be running all the time. Can't really add the load up time to the time it takes to perform the spatial queries. Others communicate with this application via a .aspx page that I set up which in turn communicates with the desktop app via .NET remoting. So, let's say I check the option to allow the service to interact with the desktop, allowing this app to be started up without actually logging into the server. What are the pitfalls with this course of action?
Steve
If it's designed to be a windowed application, it expects some form of human
interaction.
That means it is free to show dialog (modal as well a modeless) boxes (in
normal cases or in case of failures), dialog boxes that don't get closed as
there is no-one available to click a button or press a key.
It also expects the user profile to be available and accessible, which is
not the case as it runs in the context of a non interactive user
(LocalSystem).
It also expect to have access to the HKCU registry hive, which again is not
the case as the hive is not loaded.
These are some of the potential problems, but there could be more, for
instance what resources (local and remote) is the application (running as
LocalSystem) required to have access to.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Glenn |
last post by:
I have used this code successfully in a form application.
I tried to add the same code in a service and have not
been able to get the application to start. I have the
service starting with a local account and the Interact
with the Desktop is Checked. Windows media player seems to
start but then closes almost immediately. I would
appreciate...
|
by: karl |
last post by:
I have a windows service that kicks off a 'monitor' thread which in
turn kicks off 4 additional threads. These 4 threads basically are
listen on a designated socket and report back any errors (exceptions)
to the monitor thread.
Of course, all works well on my box. Yesterday I installed the .NET
Framework 1.1 on a new server and then...
|
by: Razzie |
last post by:
Hey all,
I wrote a Windows Service. When I test it on my developement machine (winXP)
it works fine. It starts ok, never crashes, etc.
When I install the service on another machine (win2000) it *sometimes*
crashes upon starting. The progressbar you get when you manually start the
server will very slowly progress, and when it hits 100% after...
|
by: Kristof Despiere |
last post by:
Suppose you have one domain, filled with a couple of users. What needs to be
done now is I need to start a windows application from a webform by pressing
a button on the webform (for example).
The problem is that the user who "owns" the service is always the ASPNET
account. That's not good since you don't see the actual application (because...
|
by: tshad |
last post by:
I have a Windows Service I created that just sets a timer and writes to
EventLog every 10 seconds.
It installed fine and it actually starts. But it says it doesn't. The
progress bar shows the progress fine until it hits about halfway. It then
stops there for about 4 or 5 seconds then goes a little farther. I then get
a message:
Could...
| |
by: hogcods |
last post by:
I'm having a strange problem with a service I developed. After installing the service on the target machine, I'm trying to start it using the Services admin window. I get the "Windows is starting" status window, but it times out - even though the application's log file says that it did start. The service's OnStart event spawns a thread and exits -...
|
by: Johnny Fugazzi |
last post by:
OK, I created my handy little windows service and created an MSI installer
using the Deployment tool in VS.net with Custom Actions according to the
msdn help.
Worked great, with one little hitch. The Service is installed and marked
for Automatic startup, but the service is not starting with windows. If i
reboot and then check the...
|
by: Arnie |
last post by:
We're using the ServiceController class provided by the .NET Framework,
programming in C#. We are using the Start() method to start a service from
another service. This works fine most of the time, but occasionally after a
system startup (where the service doing the starting of the other is
automatically started by Windows XP) the...
|
by: Benzi Eilon |
last post by:
I have written a C# application which should run as a Windows
Service. I must avoid having multiple instances of the application
on one machine so I inserted the following code at the beginning
of the Main() function:
// if this is not the first instance of this application, exit
// immediately. Allow only one instance in the system
if...
|
by: eliasen |
last post by:
Hi
I have created a Windows Service using C# and .NET2.0. The service is
quite simple - right now it doesn't do anything except throwing an
exception in the OnStart method. It used to something more, but I
couldn't get it working, so I boiled it down to the exception to test.
Anyway, the service can be installed using InstalUtil but when...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |