473,651 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.net windows service

NG
Hi All
I made a windows service in C#. Now I have a situation where I need to
invoke an exe with some UI. Assuming that the computer running this service
will always be logged in, can anyone please provide me a sample code to
invoke an exe from windows service in .net.
I tried a few methods that I found on the net but they seem to invoke
something in the background which actually does not work.
Any help is much appreciated.
Thanks in advance.
Best regards,
Nitesh Gupta
Dec 1 '05 #1
13 1938
KJ
You already tried the Process class? Perhaps you merely need to change
the ServiceControll er.ServiceType to 256 (InteractivePro cess)?

Dec 1 '05 #2
NG
Thanks for the reply KJ.
Yes, I used Process class..

I did this::
System.Diagnost ics.Process p = new System.Diagnost ics.Process();

p.StartInfo.Fil eName="notepad. exe"; // I have a different program to be run

bool x=p.Start();
Could you please give me a sample code snippet for the
ServiceControll er.ServiceType that you mentioned. A little guideline/hint
might also help me to get me started on the right path. I am not sure where
to set that property you mentioned.

Thanks,
Nitesh
"KJ" <n_**********@m ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
You already tried the Process class? Perhaps you merely need to change
the ServiceControll er.ServiceType to 256 (InteractivePro cess)?

Dec 1 '05 #3
NG
I am able to achieve this if I check the option "Allow service to interact
with desktop" in service properties from MMC. Not sure how to set this
option programmaticall y.
Dec 1 '05 #4
You can set it at installation time. MSI allow you to set it.
To set by .NET source code, you will need to use WMI (System.Managem ent
namespace), or invoke Windows API.

Note that ServiceControll er.ServiceType is readonly. And the
System.Configur ation.Install.I nstaller you add for your service (which
can be used with installutil.exe ) does not support this property.

Thi

Dec 1 '05 #5
On Thu, 1 Dec 2005 15:10:27 +0530, NG wrote:
I am able to achieve this if I check the option "Allow service to interact
with desktop" in service properties from MMC. Not sure how to set this
option programmaticall y.


Be carefull when starting a UI application from a Windows Service. Unless
your Windows Service is running under a limited Windows Account (which is
not the case by default), starting a UI appplication from the service means
giving Administrator rights to potentially anybody using the machine (even
if the users are logged in a limited Windows account).
Dec 1 '05 #6

"NG" <xgniteshATyaho oDOTcom> wrote in message
news:eW******** ******@TK2MSFTN GP12.phx.gbl...
I am able to achieve this if I check the option "Allow service to interact
with desktop" in service properties from MMC. Not sure how to set this
option programmaticall y.

Use this option only for debugging, Windows Services should otherwise never
interact with the logged-on user.
Note that "Interact with desktop" services will not work in Vista.

Willy.
Dec 1 '05 #7
KJ
Hi Nitesh, I do have code to do this. Actually, as I remember it is
either a win32 call or a registry change call. I will post it tonight
(12/1/05)

Dec 1 '05 #8
KJ
Nitesh,

As promised, here is the code.

This code is written in the ServiceInstalle r class (subclass of
System.Configur ation.Install.I nstaller), and the method to make it
interactive is called in the constructor. Hope this helps.

public EnactmentServic eInstaller()
{
// This call is required by the Designer.
InitializeCompo nent();
try {
if
(bool.Parse(Con figurationSetti ngs.AppSettings["InteractiveMod eInstall"].ToString()))
{
SetInteractiveB ool();
}
} catch (Exception exp) {
Trace.WriteLine (exp);
}
}

private void SetInteractiveB ool() {
// Here is where we set the bit on the value in the registry.
// Grab the subkey to our service
RegistryKey ckey = Registry.LocalM achine.OpenSubK ey(
@"SYSTEM\Curren tControlSet\Ser vices\" +
StringEnums.Ena ctmentWinServic eName, true);
// Good to always do error checking!
if(ckey != null) {
// Ok now lets make sure the "Type" value is there,
//and then do our bitwise operation on it.
if(ckey.GetValu e("Type") != null) {
ckey.SetValue(" Type", ((int)ckey.GetV alue("Type") | 256));
}
}
}

Dec 2 '05 #9
NG
Thanks to all of you for your valued suggestions. Thanks KJ for the code
sample. It helps me to proceed in the right direction.
Best regards,
Nitesh
Dec 2 '05 #10

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

Similar topics

11
2259
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
5682
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the service System.ServiceProcess.ServiceBase don't catchWindows messages like mouse or timer messages. Any Idea? Thanks,
9
7252
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
1
3446
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
3930
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
3
3684
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with no problems. However, I am not able to start or stop the service unless I go through the process of impersonating an administrative user. (See MSDN KB 306158) Since it appears to be a privilege issue, I set the folders in IIS holding the Web...
2
6888
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
4
4174
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.
5
3296
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
1
2081
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding, endpoint etc. programmatically in the Program.cs file. Any idea what I might be doing wrong? Cheers,
0
8275
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
8792
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8457
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
8571
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
5605
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
4143
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
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.