windows-services

Starting a service in ASP.NET/C# with the right permissions

拈花ヽ惹草 提交于 2019-12-20 06:02:49
问题 on my website (written in ASP.NET/C#) I want the moderaters to be able to start a certain service. The code I have for this is: ServiceController svcController = new ServiceController("InvidualFileConversion"); if (svcController != null) { try { svcController.Stop(); svcController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10)); svcController.Start(); } catch (Exception ex) { // error } } Now when I run this I get the error "Cannot open InvidualFileConversion service

How to start /stop a windows service through a Windows Form application

☆樱花仙子☆ 提交于 2019-12-20 05:50:26
问题 I wish to start and stop another Windows Service application via my WIndows Form application. Ons tart of my application I wish to start the Windows service, and on application exit I wish to stop the service. How can this be achieved? 回答1: You want to use the ServiceController class. Initialize it with your service name, and call Start() and Stop() methods. using System.ServiceProcess; ServiceController sc = new ServiceController("My service name"); if (sc.Status == ServiceControllerStatus

Calling ServiceBase.OnStart and OnStop… same instance?

点点圈 提交于 2019-12-20 05:24:31
问题 So I've got a Windows service written in c#. The service class derives from ServiceBase , and starting and stopping the service calls instance methods OnStart and OnStop respectively. Here's SSCE of the class: partial class CometService : ServiceBase { private Server<Bla> server; private ManualResetEvent mre; public CometService() { InitializeComponent(); } protected override void OnStart(string[] args) { //starting the server takes a while, but we need to complete quickly //here so let's

InvalidCastException of a Activator.CreateInstance object during an installation procedure

爷,独闯天下 提交于 2019-12-20 04:06:25
问题 I have the following procedure private static IMyInterface OpenInstance( string assemblyPath, string classType, string assemblyName, out AppDomain domainInstall) { IMyInterface interface = null; AppDomainSetup domaininfo = new AppDomainSetup(); domaininfo.ApplicationBase = assemblyPath; domainInstall = AppDomain.CreateDomain("PathInstall", null, domaininfo); ObjectHandle handleService = null; try { handleService = Activator.CreateInstance( domainInstall, assemblyName, classType, true, System

InvalidCastException of a Activator.CreateInstance object during an installation procedure

送分小仙女□ 提交于 2019-12-20 04:05:26
问题 I have the following procedure private static IMyInterface OpenInstance( string assemblyPath, string classType, string assemblyName, out AppDomain domainInstall) { IMyInterface interface = null; AppDomainSetup domaininfo = new AppDomainSetup(); domaininfo.ApplicationBase = assemblyPath; domainInstall = AppDomain.CreateDomain("PathInstall", null, domaininfo); ObjectHandle handleService = null; try { handleService = Activator.CreateInstance( domainInstall, assemblyName, classType, true, System

C# - from time to time check if a file exists and read from it

给你一囗甜甜゛ 提交于 2019-12-20 03:55:11
问题 I creating an windows service which will from time to time check if a certain exists and if it does, then reads from it, sends data to a server and move a file to another folder. A file's size is about 1-3 Mb. I think I will use System.Threading.Timer here to check if a file exists. What do you think of it? And another question. If a file is being copied then my app must not read from it. It should wait until copying is done. Only after that it must read from it and does other activities. So

Service In Perpetual “Starting” Status

旧街凉风 提交于 2019-12-20 03:29:14
问题 I've written a windows service in C# that converts wav files into mp3 and then stores them on a remote server. On my development rig (OS: WinXP SP3) the service starts up fine and runs the way it's supposed to. When I installed it the production machine (OS: WinServer 2000), upon starting the service it fails to start in a timely fashion, and remains in a constant "Starting" status. The program is clearly working though since the files are being converted and transferred. My hunch is that the

ServiceBase service error 193:0xc1 on Windows XP

杀马特。学长 韩版系。学妹 提交于 2019-12-20 03:27:09
问题 I have a service that I've built using the C# ServiceBase class. It works when I run it in Windows 7 and Windows Server 2008; however, it doesn't work on Windows XP. I created the service using sc create PBUService binpath= "C:\PBULogger.exe" . This is the correct path. Nothing is logging in the Event Viewer under anything and my exception handling code doesn't fire either. I thought maybe I didn't have the correct .NET version installed, but I have 4.0 installed on the XP machine. However, I

Get the disabled status of a Windows Service

房东的猫 提交于 2019-12-20 02:56:36
问题 I have written a windows service and has set its startup type to be 'Automatic'. But after installing the service a user can change its type to 'disabled'. Is there a way by which I can identify the status of this service after service installation? Can I prevent a user from changing the startup type so that it will always be 'Automatic'? Thanks 回答1: There is no API for doing this, but you can check the service start mode in the registry, at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet

ServiceController.start() and ServiceController.stop() are throwing exceptions?

丶灬走出姿态 提交于 2019-12-20 02:31:10
问题 The following code is throwing Exception. I don't get what mistake I am making in the code. Can somebody help me figure out please. I think it is of some security rights issue. If so, how can I give the security rights to any user or application to access this windows service programmatically? Dim sc As New ServiceController sc.ServiceName = "DataLoad" If sc.Status = ServiceControllerStatus.Stopped Then sc.Start() Else sc.Stop() End If Exception : System.InvalidOperationException: Cannot open