windows-services

HTTP 503 Service is unavailable when trying to browse signalr/hubs

大兔子大兔子 提交于 2019-11-29 09:12:56
I have a windows hosted SignalR hub created in VS2012: public class Startup { public void Configuration(IAppBuilder app) { app.UseCors(CorsOptions.AllowAll); app.MapSignalR(); } } public static class SignalR { public static void Start() { const string url = "http://*:8080"; WebApp.Start<Startup>(url); } } public class Broadcaster : Hub { public void SendDownloadResult(bool result, string device, string description, string connectionId, string task) { var context = GlobalHost.ConnectionManager.GetHubContext<Broadcaster>(); context.Clients.Client(connectionId).sendDownloadResult(result, device,

How to call a WebAPI from Windows Service

你。 提交于 2019-11-29 08:43:41
问题 I have an application written in Windows Service and this app need to make a call to a WebAPI written in Asp.Net MVC 4 WebAPi. this method in WebAPI return a DTO with primitive type, something like: class ImportResultDTO { public bool Success { get; set; } public string[] Messages { get; set; } } and in my webapi public ImportResultDTO Get(int clientId) { // process.. and create the dto result. return dto; } My question is, how can I call the webApi from the Windows Service? I have my URL and

Programmatically Install Windows Service On Remote Machine

对着背影说爱祢 提交于 2019-11-29 07:55:29
Similar to https://stackoverflow.com/a/467565/774828 which shows how to start and stop an existing Windows service on a remote machine, I am trying to install a Windows Service on a remote machine. I can start and stop the services on the remote machine fine, but I can't find how to install a new service remotely, without resorting to calling the sc.exe process ( https://stackoverflow.com/a/1159059/774828 ) which I want to avoid if possible. I know there is a System.Configuration.Install.ManagedInstallerClass.InstallHelper method, but I cannot get this to work to install on a remote machine.

Granting remote user (non admin) the ability to enumerate services in Win32_Service in namespace cimv2 using WMI & C#

时光怂恿深爱的人放手 提交于 2019-11-29 07:51:41
I'm creating a watch dog service that will be monitoring other services on various remote servers (all in the same domain). The user that I'm using to connect to the remote servers is not an admin. When I try to enumerate the services in the Win32_Service class, I get an access denied error. I've given the user 'Remote Enable' & 'Enable Account' persmissions to the Root\CIMV2 namespace in the WMI Control. I am able to connect to the server with the following code. The object ServiceListItem is just a simple class that contains the server name and the service name: SecureString secureString =

Protecting a Windows Service from untrusted users

百般思念 提交于 2019-11-29 07:48:23
How can I prevent users from tampering with, stopping or crashing a Windows Service that is doing work in the background that may take a while to complete? Upon receiving a stop request, the service should wait until the work is complete before stopping. There is the CanStop flag for services, but I'm not sure how to respond to the OnStop message. And if the user does try to crash the service, how can I prevent further tampering? Edit: Generalised question from parental control to any background process. Users have to have admin privs to stop services. I don't think there is a foolproof way to

How do I set the a windows service log on credentials?

隐身守侯 提交于 2019-11-29 07:41:04
How do I programmatically set the "Log On" credentials for an arbitrary Windows service using c# (wmi/interop is fine)? Note, my program is running as an administrator and I need the change to persist (for all subsequent service restarts) Ideally the method has the following sig: void SetWindowsServiceCreds(string serviceName, string username, string password) { // TODO write me } [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ChangeServiceConfig(IntPtr hService, UInt32 nServiceType, UInt32 nStartType,

launch process from Session 0 Isolation

♀尐吖头ヾ 提交于 2019-11-29 07:21:05
On Windows 8.1 I have a service that starts PowerShell scripts. The service runs as “nt authority\system” in Session 0 Isolation. Any process that I spawn from PowerShell runs as “nt authority\system” in Session 0 Isolation. I need to run a script that is under a user account out of session 0 and not the system account. I have tried this Start-Process "$PsHome\PowerShell.exe" -Credential $pp -ArgumentList $script -wait and PsExec specifying which session I want with "-I 1" argument. & PsExec.exe "Install.bat" -i 1 -accepteula -u "domain\user" -p "awesomePassword" -w "startdir" -h I have tried

How do I safely stop a C# .NET thread running in a Windows service?

℡╲_俬逩灬. 提交于 2019-11-29 06:02:44
I am maintaining some code which looks something like this. It's a Windows service which does some work every 30 minutes. The ActualWorkDoneHere method takes about 30 seconds to run, but if it is stopped while running it can leave things in a bad state. What is the best way to prevent that from happening? Should I replace the While(true) with a boolean which is set to false in the onstop method (removing the thread Abort call)? Is there some way to tell if a thread is sleeping? namespace WorkService { public partial class WorkService : ServiceBase { private Thread _workerThread = null; public

Sharing code between 2 projects without a dll

笑着哭i 提交于 2019-11-29 05:50:02
问题 How can I have code-sharing between two projects without making a dll? The issue is: I have a tool that syncs users & groups from LDAP to a database. Now the tool is a windows service, but testing it as such is very difficult and time consuming. Which is why I made a console application where I can test the LDAP syncing, and then just copy the respective sourcecode-files over to the service project. But... keeping the common files in sync is a bit of a problem. I don't want to make a dll,

How to remotely control a Windows Service with ServiceController?

廉价感情. 提交于 2019-11-29 05:34:40
I'm trying to control Windows Services that are installed in a remote computer. I'm using the ServiceController class. I have this: ServiceController svc = new ServiceController("MyWindowsService", "COMPUTER_NAME"); With this, I can get the status of the Windows Service like this: string status = svc.Status.ToString(); But I can't control the Windows Service (by doing svc.Start(); or svc.Stop(); ). I get the following exception: Cannot open Servicexxx service on computer 'COMPUTER_NAME' That's normal, I suppose there is something to do with access permissions. But how? I've looked into Google