windows-services

Error “Settings to access printer 'printername' are not valid” when printing from Windows service

旧城冷巷雨未停 提交于 2019-11-27 22:16:32
问题 I get the error mentioned when printing to a network printer. The error does not occur when run under XP/Win2003, in a WinForm app or when a local printer is used. The error does only occur when run as a Windows Service under Vista/Win7/Win2008 and printing to a network printer. The Windows service runs under a network user that has access to the network printer. Before I print I check if the printername (including network path) is ok by looping through the available printers. How can this be

Show a message box from a Windows Service

元气小坏坏 提交于 2019-11-27 21:59:20
Can you display a message box (or any form of notification) from a windows service? Can't get it to work. I used: global::System.Windows.Forms.MessageBox.Show("A fatal error occurred. " + ServiceName + " is now terminating."); but it didn't work and just produced an error. No, you cannot show a message box from a service. If you want to report errors, the standard way to do this is with the event log . For more "advanced" kinds of UI (not just error reporting), the way this is typically done is via a regular windows application that you put in the user's Startup folder (or the Run key in the

EventLog write permissions

你。 提交于 2019-11-27 21:52:44
My question is related to write permissions to the Windows Event Log. I have looked around several posts concering this, and have found some ways to solve my problem, but none of these are acceptable for my current scenario. I use C# in .NET 4.0. I use the EventLog class: EventLog class In short, I need to see if there is a way to impersonate or authenticate with an authenticated user and password to reach the right I need to write to the Event Log. The server will always be in the Windows Server family, but the version may vary. My application is a Windows Service running with one of the

Setting recovery options on windows services

柔情痞子 提交于 2019-11-27 21:21:19
I've recently written a small class to help me change recovery options on a windows service (most of code I found online somewhere). The code creates a FailureAction for the first, second, and subsequent failures. Each Failure object contains a type (None, Restart, Reboot, RunCommand), and a Delay (int) in milliseconds. These objects are packaged inside a struct and passed into ChangeServiceConfig2 (WinAPI P/Invoke). However, when I actually right-click on a service on the console and go to the Recovery tab, you can only set the delay ("Restart server after" field) once for all failures (first

what is the maximum time windows service wait to process stop request and how to request for additional time

半世苍凉 提交于 2019-11-27 21:18:53
I have written a windows service in c# that process a lot data. when we stop it try for sometime 20/30 seconds and then throws exception. I want to implement ServiceBase.RequestAdditionalTime() in OnStop event. I want to know the exact timeout after which windows service throws the exception, so that I can request additional time just before it. I searched but did not find this default stop timeout value. I wrote the following code to achieve it. protected override void OnStop() { int timeout = 10000; var task = Task.Factory.StartNew(() => MyTask()); while (!task.Wait(timeout)) {

C# Run Windows Form Application from Service (and in Vista)

十年热恋 提交于 2019-11-27 21:06:28
问题 I am writing an application in C# that needs to run as a service but also have user interaction. I understand that services have no UI, etc, so I've divided up my program into a windows form application and a service that can communicate with each other. The problem I'm having is that I need the service to make sure the windows form application is always running and restart it if it is not. I'm able to detect if it is running, and restart it with the following code on Windows 2000/XP: System

WCF Windows Service - Long operations/Callback to calling module

a 夏天 提交于 2019-11-27 20:49:06
I have a Windows Service that takes the name of a bunch of files and do operations on them (zip/unzip, updating db etc). The operations can take time depending on size and number of files sent to the service. (1) The module that is sending a request to this service waits until the files are processed. I want to know if there is a way to provide a callback in the service that will notify the calling module when it is finished processing the files. Please note that multiple modules can call the service at a time to process files so the service will need to provide some kind of a TaskId I guess.

How to change user credentials of windows service from command line?

廉价感情. 提交于 2019-11-27 20:28:37
问题 How to change user credentials of windows service from command line? 回答1: sc.exe config "Service Name" obj= "DOMAIN\User" password= "password" type= own See Shortcut Setting Log-On Credentials for Windows Services » jonathanmalek.com. @MattT points out that on Windows Server 2008R2 you have to add type= own , but prior to that version it isn't necessary. In PowerShell 3+, you can avoid escaping the arguments with the stop-parsing symbol: --% sc.exe --% config "Service Name" obj= "DOMAIN\User"

Windows 2008 RenderFarm Service: CreateProcessAsUser “Session 0 Isolation” and OpenGL

拜拜、爱过 提交于 2019-11-27 20:17:49
I have a legacy Windows server service and (spawned) application that works fine in XP-64 and W2K3, but fails on W2K8. I believe it is because of the new " Session 0 isolation " feature. Consequently, I'm looking for code samples/security settings mojo that let you create a new process from a windows service for Windows 2008 Server such that I can restore (and possibly surpass) the previous behavior. I need a solution that: Creates the new process in a non-zero session to get around session-0 isolation restrictions (no access to graphics hardware from session 0) - the official MS line on this

Impersonate user in Windows Service

允我心安 提交于 2019-11-27 20:09:43
I am trying to impersonate a domain user in a windows service with the service logged in as the Local System Account. So far, I am only able to get this to work by logging the service and set the process using the user credentials, like the following. ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = CommandDetails.Command; startInfo.WorkingDirectory = Settings.RoboCopyWorkingDirectory; startInfo.Arguments = commandLine; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; //