windows-services

How do I detect that my application is running as service or in an interactive session?

半世苍凉 提交于 2019-12-03 23:28:46
I'm writing an application that is able to run as a service or standalone but I want to detect if the application was executed as a service or in a normal user session. I think you can query the process token for membership in the Interactive group. From http://support.microsoft.com/kb/243330 : SID: S-1-5-4 Name: Interactive Description: A group that includes all users that have logged on interactively. Membership is controlled by the operating system. Call GetTokenInformation with TokenGroups to get the groups associated with the account under which the process is running, then iterate over

Get the PID of a Windows service

本小妞迷上赌 提交于 2019-12-03 23:20:46
Could anyone help me to know how to get the PID of a Windows service? I need to get the PID in order to run the following command: Process.Start(new ProcessStartInfo { Filename = "cmd.exe", CreateNoWindow = true, UseShellExecute = false, Arguments = string.Format("/c taskkill /pid {0} /f", pidnumber) }); M C Assuming you know the name of the EXE the service uses and there is exactly one of them: int procID = Process.GetProcessesByName("yourservice")[0].Id; The method Process.GetProcessesByName("yourservice") returns an Array of Processes with your specified name, so in case you don't know how

Launching a .Net winforms application interactively from a service

一笑奈何 提交于 2019-12-03 22:57:37
问题 Environment - VS2008, Vista SP1. I have written a process management service which can launch applications either in session 0 or the interactive console (usually 1). Please note this is NOT the normal mode of operation, it's for in-house debug purposes only. In the field, these processes will be safely hidden away in session 0. Security concerns do not apply. Clearly people aren't reading this: security concerns do not apply. We have dozens of existing server apps (NOT services) written like

Is it possible to observe Rss feed change in C#?

我与影子孤独终老i 提交于 2019-12-03 22:14:15
I want to create a service that would listen to few Rss feeds and parse new feeds to jSon for further use. Is it possible to observe to feed changes and if yes then how? thanks Check out the System.ServiceModel.Syndication.SyndicationFeed namespace in the framework - it has pretty much everything you need to download feeds. Scott Guthrie has a couple of good example blog posts about reading feeds here and here . The only way to observe RSS feed changes is to poll the feed by requesting it over a set interval of time. This is because a feed is typically delivered over HTTP, which is a stateless

Want to script Windows WMI (wmiprvse.exe) to release handle on file

十年热恋 提交于 2019-12-03 21:43:06
I'm working with a VB Script file written by someone else that uses Windows Management Instrumentation (WMI) calls to check on the status of several Windows Services. This script runs every few minutes on set schedule. I need to upgrade/replace the .exe for those services. I stop the VB Script, stop the services, and uninstall the services so they no longer appear in the Services panel (services.msc). Unfortunately, WMI (wmiprvse.exe) still has a handle on the service .exe files. I can release the handle by rebooting the system, but I want to avoid that if at all possible so this can be a

create service on windows

泄露秘密 提交于 2019-12-03 21:41:52
I am having trouble starting my service on my pc. My code is based on this article http://www.gamedev.net/reference/articles/article1899.asp When i call installService from my int main(int argc, char *argv[]), it is registered successfully (i can see it in msconfig and services.msc). However it has not started. I manually start the service via services.msv and i get the error "Error 2: system cannot find the file specified". Why is this? i registered the services no more then a min ago, my external HD is still on (where this is currently stored. i'll move a nondev version to c:/ when its ready

C# Windows service needs to make registry changes

做~自己de王妃 提交于 2019-12-03 21:40:10
问题 I have a service that needs to update the registry every 5 minutes (counteract gpo). The code runs fine in a regular application, but when I put it in a windows service, it doesn't make the changes. I am using the local system account for the service and it is not throwing any exceptions The code below works in a regular console app but not in the service: RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true); if (key != null) { key.SetValue("ScreenSaverIsSecure",

How do you write and use a Windows Service in C#? [closed]

こ雲淡風輕ζ 提交于 2019-12-03 21:22:36
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . How do you write and use a Windows Service in C#? What is the best way to that ? 来源: https://stackoverflow.com/questions/18573024/how-do-you-write-and-use-a-windows-service-in-c

Programmatically add an windows service to Windows Firewall (During Installation) [duplicate]

感情迁移 提交于 2019-12-03 20:47:07
This question already has answers here : Closed 7 years ago . Possible Duplicate: Programmatically add an application to Windows Firewall in my solution i have an windows service project and installer to install this service How i can add this service to Windows Firewall During Installation. Assuming we're using a Visual Studio Installer->Setup Project - You need an installer class like this inside an assembly that's being installed, and then make sure you add a custom action for the "Primary output" in the install phase. using System.Collections; using System.ComponentModel; using System

Is it possible to log who started or stopped a windows service?

你离开我真会死。 提交于 2019-12-03 20:42:47
问题 I have some windows services written in C#. When somebody stops or starts the service, I would like to be able to determine who it was and log that information. I tried logging Environment.UserName but that evaluates to SYSTEM even on my local machine. Also, for the time being these services are running on Windows 2000 server. 回答1: Within the Event Viewer (Control Panel | Administrative Tools | Event Viewer) on the System tab the Service Control Manager logs who started and stop each event. I