the process and services...
-
Hi every body i want to ask: how we can prevent the user from ending the process from the task manager? the a second question is how we can make the service interactive with the desktop i know that there is ServiceType calss but when i try to use it the service dos'nt interact with the desktop and here is the segment of the code which i wrote .......... ........... private void InitializeComponent() { this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); // // serviceProcessInstaller1 // this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService; this.serviceProcessInstaller1.Password = null; this.serviceProcessInstaller1.Username = null; // // serviceInstaller1 // this.st=System.ServiceProcess.ServiceType.InteractiveProcess; this.serviceInstaller1.ServiceName = "Service2"; this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic; // // ProjectInstaller // this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.serviceProcessInstaller1, this.serviceInstaller1,this.st }); .............. .............. note i install the service by setup project with regards
-
Hi every body i want to ask: how we can prevent the user from ending the process from the task manager? the a second question is how we can make the service interactive with the desktop i know that there is ServiceType calss but when i try to use it the service dos'nt interact with the desktop and here is the segment of the code which i wrote .......... ........... private void InitializeComponent() { this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); // // serviceProcessInstaller1 // this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService; this.serviceProcessInstaller1.Password = null; this.serviceProcessInstaller1.Username = null; // // serviceInstaller1 // this.st=System.ServiceProcess.ServiceType.InteractiveProcess; this.serviceInstaller1.ServiceName = "Service2"; this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic; // // ProjectInstaller // this.Installers.AddRange(new System.Configuration.Install.Installer[] { this.serviceProcessInstaller1, this.serviceInstaller1,this.st }); .............. .............. note i install the service by setup project with regards
Wail A.Salem wrote: how we can prevent the user from ending the process from the task manager? You can't. But you can respond to notification that a user is killing your process. Handle the
Closing
orClose
event of your main form (the one you pass directly or indirectly toApplication.Run
). If your code is not finished in a timely manner, your process will be killed. There are a few other ways as well, but I'll leave this as an exercise for you. I recommend reading through the Windows Management APIs section of the MSDN Online Library[^]. As for the second question, you have to write this to the registry yourself. So add a registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\<YourServiceName>\Type such as 288 (256 for "Interact with desktop" OR'd with 32 for the service type), or whatever is appropriate for your service type so long as you perform a bitwise OR with 256 and run it as the LocalSystem (default). If you run it as a user, then the service can only interact with that user's desktop (assuming the user has an associated desktop session and can log in locally).Microsoft MVP, Visual C# My Articles