windows-services

detect shutdown in window service

半城伤御伤魂 提交于 2019-11-29 12:15:19
问题 i have a windows service that get user details and save the result into log text file. and, my problem is when i shut down or log off my system, i also would like to save the time that i down my system into that log file. but, i don't know how to do that. I checked the winproc method to detect shutdown operation but i was not able to use it on window service, on googling found it can be used with forms only. how can we detect user have clicked shutdown or log off and do some action. so,please

Can you write Windows services in Powershell

荒凉一梦 提交于 2019-11-29 12:02:18
I have written a program in PowerShell that loops and checks stuff. I would like to convert this into a Windows service. I've created a Windows service (in Admin->Services) but I can't start it. I'm pretty sure I'm missing the proper interface that the system needs to call into in order to start/stop/pause/etc the service. I can find plenty of examples when it comes to doing it in VB/C#/MS-lang but nothing about how to do it using PowerShell. Is there any documentation (or preferably code examples) out there to help with this? If you absolutly want to execute your PowerShell code into a

How to make a Windows service with parameters?

心不动则不痛 提交于 2019-11-29 11:58:03
问题 I have written a Windows service, of which I want to have 1 instance running per customer. This is because the customers each have their own DB with identical schemas; the only difference between the Windows services is that they will each have a different parameter corresponding to the customer DB that they're designated to serve. (And I can't have one service with multiple worker threads, because the DB connection uses a static variable, which I can't fiddle with across threads.) I found

Windows Service runs but stops processing after two days

家住魔仙堡 提交于 2019-11-29 11:42:42
I've seen a fair few posts regarding this issue but non that seem to fit my criteria. Having said that, this is the first one that I've built that "needs" to perform a tremendous amount of logic. All works great for a couple days but after that logic stops working with no log in the event viewer nor firing of an email (exceptions). I'm wondering if my logic is not correct... Looking for advice and pointers. public partial class QuayService : ServiceBase { private System.Timers.Timer m_mainTimer; private bool m_timerTaskSuccess; private Email _email; public QuayService() { InitializeComponent()

IAsyncOperation await in Windows Service: “Type is defined in an assembly that is not referenced…”

若如初见. 提交于 2019-11-29 11:40:12
I have a Windows Service (created using this tutorial ). And I am trying to run an IAsyncOperation : var uri= new Uri(@"uri/to/second/app"); var options = new LauncherOptions { TargetApplicationPackageFamilyName = "second-app-guid" }; var results = await Launcher.LaunchUriForResultsAsync(uri, options); However, I get the following error from the await : The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. The type

Why doesn't the RequestAdditionalTime() method work on restart in Vista/7?

倖福魔咒の 提交于 2019-11-29 10:21:35
I have been doing some extensive testing of a Windows Service I have been writing in C# .Net 3.5. I am having trouble getting Windows to give me enough time for my service to shutdown properly when I restart or shutdown the computer even though I am invoking the RequestAdditionalTime() method which should update the SCM and keep my service running. My code works properly if I manually stop the service however. I have primarily been testing this code in Windows Vista and Windows 7, upon deciding to test the code in Windows Xp everything worked perfectly. Does anyone know why this call does not

running a batch file from C#

試著忘記壹切 提交于 2019-11-29 10:14:28
UPDATE ** STILL LOOKING FOR A CORRECT ANSWER ** I have the following code in my windows service and I want to run a batch file. I want the command prompt window up so I can see progress here is my code but my batch file code doesnt work using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.IO; namespace Watcher { public partial class Watcher : ServiceBase { public Watcher() { InitializeComponent(); FolderWatcher.Created += FolderWatcher_Created;

Office Interop Does Not Work in Windows Service

最后都变了- 提交于 2019-11-29 09:53:19
问题 I have a very weird issue with Microsoft Office. I have a common library whose sole purpose is to open whatever word document file type is passed to it (by a full file path...) and save that opened word document as a pdf file. The weird issue is that if I consume that library from a windows service, whenever it attempts to open the word document, I get a null... aka, the word document never got opened. If however I consume the library from a WPF or Windows Form application I never have any

How to deploy Windows Service projects with Team Build 2010

北城以北 提交于 2019-11-29 09:29:06
问题 I have a VS2010 solution, which includes several Windows Service projects. I need to deploy these services as part of a build in Team Build 2010, and the Windows Services have to be deployed on several Windows Server machines. How can I do this? 回答1: You could conditionally invoke the SC.exe command from your Windows Service project file (*.csproj) to install the Windows Service on a remote machine. Here's an example: <PropertyGroup> <DeployWinService>false</DeployWinService> <WinServiceName

How can I receive OutputDebugString from a service?

↘锁芯ラ 提交于 2019-11-29 09:26:50
I'm trying to catch all OutputDebugString messages (including those from services) using the following code. It worked fine until I migrated to Windows 7. The problem is that since Windows Vista services are running in the low level Session #0, some people say that it's impossible to catch them and some that it is. What do you think? Is it possible to modify the following code by increasing some rights to be able to receive OutputDebugString messages from the Session #0? In other words; is it possible to share DBWIN_BUFFER in the session #0 with Session #1? I would say it should be possible