473,698 Members | 2,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Starting a process from inside a windows service

Hi,

I am trying to start a process from inside a .NET service. The process is a
simple GUI app, the service will start up the GUI and then stop itself. The
service starts the app, but no GUI appears. However, I can see the
application running in the task manager. I made sure that CreateNoWindow was
set to false and still no GUI appears. If i run the application by double
clicking on it, the GUI appears fine. Here is the code:

Process p = new Process();
p.StartInfo.Fil eName = _basedir + "DbUpdate.e xe";
p.StartInfo.Win dowStyle = ProcessWindowSt yle.Normal;
p.StartInfo.Cre ateNoWindow = false;
p.StartInfo.Use ShellExecute = true;
p.Start();

Essentially, I am checking the version of a database and if it is not the
correct version, I want to stop the service and start up the updating
utility. The service runs, starts the process, and exits as expected, but
the GUI does not appear, except as a process in Task Manager. If it matters,
I am executing the code through a class using remoting and it is in the
constructor of the class. Also note that the service exits immediately after
starting the process, although I did not think that would be a problem.

If anyone has any insight into the cause of this problem, it would be very
helpful to me.

-Timothy Shih
Nov 16 '05 #1
3 3049
Timothy,

You have to check the properties of the service, and make sure that the
checkbox that says "allow service to interact with desktop" is checked.
However, this is a bad idea, because you can not guarantee that you always
have an interactive user session to show a GUI for.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Timothy Shih" <ts***@sensicas t.com> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I am trying to start a process from inside a .NET service. The process is a simple GUI app, the service will start up the GUI and then stop itself. The service starts the app, but no GUI appears. However, I can see the
application running in the task manager. I made sure that CreateNoWindow was set to false and still no GUI appears. If i run the application by double
clicking on it, the GUI appears fine. Here is the code:

Process p = new Process();
p.StartInfo.Fil eName = _basedir + "DbUpdate.e xe";
p.StartInfo.Win dowStyle = ProcessWindowSt yle.Normal;
p.StartInfo.Cre ateNoWindow = false;
p.StartInfo.Use ShellExecute = true;
p.Start();

Essentially, I am checking the version of a database and if it is not the
correct version, I want to stop the service and start up the updating
utility. The service runs, starts the process, and exits as expected, but
the GUI does not appear, except as a process in Task Manager. If it matters, I am executing the code through a class using remoting and it is in the
constructor of the class. Also note that the service exits immediately after starting the process, although I did not think that would be a problem.

If anyone has any insight into the cause of this problem, it would be very
helpful to me.

-Timothy Shih

Nov 16 '05 #2
You may want to consider a ms task/job instead. Ideally a service
shouldnt have a gui dependency
Timothy Shih wrote:
Hi,

I am trying to start a process from inside a .NET service. The process is a
simple GUI app, the service will start up the GUI and then stop itself. The
service starts the app, but no GUI appears. However, I can see the
application running in the task manager. I made sure that CreateNoWindow was
set to false and still no GUI appears. If i run the application by double
clicking on it, the GUI appears fine. Here is the code:

Process p = new Process();
p.StartInfo.Fil eName = _basedir + "DbUpdate.e xe";
p.StartInfo.Win dowStyle = ProcessWindowSt yle.Normal;
p.StartInfo.Cre ateNoWindow = false;
p.StartInfo.Use ShellExecute = true;
p.Start();

Essentially, I am checking the version of a database and if it is not the
correct version, I want to stop the service and start up the updating
utility. The service runs, starts the process, and exits as expected, but
the GUI does not appear, except as a process in Task Manager. If it matters,
I am executing the code through a class using remoting and it is in the
constructor of the class. Also note that the service exits immediately after
starting the process, although I did not think that would be a problem.

If anyone has any insight into the cause of this problem, it would be very
helpful to me.

-Timothy Shih

--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 16 '05 #3
Elp

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Timothy,

You have to check the properties of the service, and make sure that the checkbox that says "allow service to interact with desktop" is checked.
However, this is a bad idea, because you can not guarantee that you always
have an interactive user session to show a GUI for.


....and if your service is running under the Local System account (which is
the case most of the time unless you change it to a more restrictive
account), the GUI application you are trying to launch will have all the
Local System account right, which means even more rights than the
Administrator account! Definitely no a good idea.
Nov 16 '05 #4

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

Similar topics

0
1356
by: Trokey | last post by:
I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server is started up instead of attaching to the already running one. I have tried the following fixes with no results: 1. added these lines to my service: System.Threading.Thread.CurrentThread.ApartmentState = ApartmentState.STA; int ret =...
0
886
by: Pradeep | last post by:
HI Can we invoke a process in windows Servic Pradeep
4
4794
by: Julia | last post by:
Hi, I have two application which 'evaluate'( New FileStream(path....) relative path, when evaluating the path inside a window service it always return something like C:\\WINNT\SYSTEM32\MyPath While when evaluating it in a window application I get the correct path
1
1016
by: Stu | last post by:
Hi, I have been asked to write a little app the restarts a windows service under certain conditions. It is not a service written in .Net? thanks in advance, Stu
1
1631
by: Shane Lowenberger via .NET 247 | last post by:
Hi All, I created a Windows Service in Visual Basic.NET and am having troubles. My Service installs fine, but when I start I get two exceptions thrown in the Event Log and the service stops. Here they are: 1: System.IndexOutOfRangeException: Index was outside the bounds of the array. at ServiceName.OnStart(String args) This one happens before the service starts, then I get 2. Service cannot be started. System.InvalidCastException:...
5
1633
by: Cleyton | last post by:
Hi! I would like to know if is it possible start an application through WINDOWS SERVICE using System.Diagnostics.Process.Start()? I've tried to do this but nothing happens. Tks!
1
3284
by: Qais | last post by:
Hi there all, i am trying to work on this for past two weeks but nothing seem to work. I am trying to launch a process from windows service (i have to do this way, no other option). Windows service is running under system account with interaction with desktop enabled. The application i want launch is a vb.net gui application. I have tried using wmi, windows api, managed system.process.start method but all have one problem or the other....
1
2075
by: google | last post by:
The problematic code runs perfectly fine and unmodified when the application is executed as a standalone .exe. However when the same code is executed inside Windows Service - it locks up and waits indefinetely attempting to instantiate COM object with Activator.CreateInstance. The service impersonates local admin creadentials. I am not getting any exceptions, neither raised, nor reported in systems logs.
2
1682
by: deepadeshmukh | last post by:
How to call an external process from Windows service in C#2.0? This code doesnt works protected override void OnStart(string args) { Process.Start("C:\\Documents\\sessiondemo\\sessiondemo\\bin\\Debug\\Sessiondemo.exe"); }
1
1301
devonknows
by: devonknows | last post by:
Hi, what im aiming to do is to write a windows service which shuts down a process when a information in a .dat files changes, now the windows service installs, and runs, but.. its not doing the designated task i was hoping someone could offer some help. Language: .NET Version: Visual Studio 2005 Project: Windows Service As you open the new project () Ive added a timer (Timer1) to run the task at an interval of, 10,000. Below is the code...
0
8609
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
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...
1
8899
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
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
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.