windows-services

How do you retrieve a list of logged-in/connected users in .NET?

你。 提交于 2019-11-26 12:23:01
Here's the scenario: You have a Windows server that users remotely connect to via RDP. You want your program (which runs as a service) to know who is currently connected. This may or may not include an interactive console session. Please note that this is the not the same as just retrieving the current interactive user. I'm guessing that there is some sort of API access to Terminal Services to get this info? Magnus Johansson Here's my take on the issue: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace EnumerateRDUsers { class

Service hangs up at WaitForExit after calling batch file

喜夏-厌秋 提交于 2019-11-26 12:22:27
I have a service that sometimes calls a batch file. The batch file takes 5-10 seconds to execute: System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process proc.StartInfo.FileName = fileName; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.CreateNoWindow = true; proc.Start(); proc.WaitForExit(); The file does exist and the code works when I run the same code in-console. However when it runs inside the service, it hangs up at WaitForExit() . I have to kill the batch file from the Process in order to continue. (I am

How to start a process from windows service into currently logged in user's session

风流意气都作罢 提交于 2019-11-26 12:04:48
I need to start a program from Windows Service. That program is a user UI application. Moreover that application should be started under specific user account. The problem is that a Window Services run in session #0, but a logged in user sessions are 1,2 etc. So the question is: how to start a process from a window service in such a way that it run in currently logged in user's session? I'd emphasis on that the question is not about how to start a process under specific account (it's obvious - Process.Start(new ProcessStartInfo("..") { UserName=..,Password=..})). Even if I install my windows

How to install a windows service programmatically in C#?

落花浮王杯 提交于 2019-11-26 12:01:14
I have 3 projects in my VS solution. One of them is a Web app, the second one is a Windows Service and the last one a Setup project for my Web app. What I want is by the end of the installation of the web app in my setup project, within my custom action to try and install my windows service given that I have the location of the assembly by then. I found several errors in the code that you reused and have fixed these and also cleaned it up a little. Again, the original code is taken from here . public static class ServiceInstaller { private const int STANDARD_RIGHTS_REQUIRED = 0xF0000; private

Windows Service not appearing in services list after install

房东的猫 提交于 2019-11-26 11:57:31
问题 I\'ve created a windows service in c#, using Visual Studio 2008 I pretty much followed this: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx I created a setup project, as instructed to in the article, and ran it... it installs my service to c:\\program files\\product etc.... however, it does not then appear in the services list.. What am i missing? 回答1: The most important part of the article you linked, is here To add a custom action to the setup project 1.In Solution Explorer,

How do I restart a service on a remote machine in Windows? [closed]

偶尔善良 提交于 2019-11-26 11:55:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Sometimes while debugging, I need to restart a service on a remote machine. Currently, I\'m doing this via Remote Desktop. How can it be done from the command line on my local machine? 回答1: You can use the services console, clicking on the left hand side and then selecting the "Connect to another computer"

How to check if a service is running via batch file and start it, if it is not running?

六眼飞鱼酱① 提交于 2019-11-26 11:50:06
问题 I want to write a batch file that performs the following operations: Check if a service is running If is it running, quit the batch If it is not running, start the service The code samples I googled so far turned out not to be working, so I decided not to post them. Starting a service is done by: net start \"SERVICENAME\" How can I check if a service is running, and how to make an if statement in a batchfile? I\'m a bit confused. What is the argument I have to pass onto the net start? The

Modifying the “Path to executable” of a windows service

两盒软妹~` 提交于 2019-11-26 11:47:26
问题 I\'d like to modify the path to my application, but doing so breaks it because the service still points to the old location. By going to Administrative Tools > Services you can open a properties dialog and view the Path to executable , but there is no way to change it. Is there any way a user can modify the service path without having to reinstall the application ? 回答1: There is also this approach seen on SuperUser which uses the sc command line instead of modifying the registry: sc config

How can I run an EXE program from a Windows Service using C#?

江枫思渺然 提交于 2019-11-26 11:45:47
How can I run an EXE program from a Windows Service using C#? This is my code: System.Diagnostics.Process.Start(@"E:\PROJECT XL\INI SQLLOADER\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2\bin\Debug\ConsoleApplication2.exe"); When I run this service, the application is not starting. What's wrong with my code? Cody Gray This will never work , at least not under Windows Vista or later. The key problem is that you're trying to execute this from within a Windows Service, rather than a standard Windows application. The code you've shown will work perfectly in a Windows Forms, WPF, or

How can I verify if a Windows Service is running

亡梦爱人 提交于 2019-11-26 11:34:17
I have an application in C# (2.0 running on XP embedded) that is communicating with a 'watchdog' that is implemented as a Windows Service. When the device boots, this service typically takes some time to start. I'd like to check, from my code, if the service is running. How can I accomplish this? I guess something like this would work: Add System.ServiceProcess to your project references (It's on the .NET tab). using System.ServiceProcess; ServiceController sc = new ServiceController(SERVICENAME); switch (sc.Status) { case ServiceControllerStatus.Running: return "Running"; case