windows-services

Install a Windows service using a Windows command prompt?

隐身守侯 提交于 2019-11-26 07:52:25
问题 I want to install a Windows service using a Windows command prompt (not the Visual Studio command prompt). How do I do this? 回答1: Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this: "C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe" 回答2: Nothing wrong with SC Create command. Just you need to know the correct args : SC CREATE "MySVC" binpath

FileSystemWatcher Fails to access network drive

妖精的绣舞 提交于 2019-11-26 07:48:50
问题 I am trying to run a file watcher over some server path using windows service. I am using my windows login credential to run the service, and am able to access this \"someServerPath\" from my login. But when I do that from the FileSystemWatcher it throws: The directory name \\someServerPath is invalid\" exception. var fileWatcher = new FileSystemWatcher(GetServerPath()) { NotifyFilter=(NotifyFilters.LastWrite|NotifyFilters.FileName), EnableRaisingEvents=true, IncludeSubdirectories=true };

how to delay shutdown and run a process in window service

纵然是瞬间 提交于 2019-11-26 07:44:51
问题 I have to run a process ie a application on windows shutdown, is there any method to delay the windows shutdown and run the application in windows service... protected override void OnShutdown() { // Add your save code here // Add your save code here StreamWriter str = new StreamWriter(\"D:\\\\Log.txt\", true); str.WriteLine(\"Service stoped due to on\" + DateTime.Now.ToString()); str.Close(); base.OnShutdown(); } I have used function above which overrides the shutdown and i was able to write

Redirect stdout+stderr on a C# Windows service

戏子无情 提交于 2019-11-26 07:42:13
问题 I\'ve written a Windows service in C# using the ServiceBase helper. During its execution some procedures on an external native DLL are called. Annoyingly, those procedures write to stdout and/or stderr in a uncontrolled manner as no sources are given for this DLL. Is it possible to redirect those outputs from the C# service to a log file? 回答1: You can do this via PInvoke to SetStdHandle: [DllImport("Kernel32.dll", SetLastError = true) ] public static extern int SetStdHandle(int device, IntPtr

How to communicate with a windows service?

北城余情 提交于 2019-11-26 07:36:42
问题 I want to create a windows service that validates data and access it from another windows application, but I\'m new to services and I\'m not sure how to start. So, while the service is running, a windows application should somehow connect to the service, send some data and get a response, true or false. 回答1: I could successfully handle the (almost) same issue as yours doing the following: In your Class : ServiceBase, that represents your Service class, you might have: public Class () /

How do i create an InstallShield LE project to install a windows service?

为君一笑 提交于 2019-11-26 06:54:57
问题 I downloaded Visual Studio 2012 yesterday when it was released on MSDN. I have noticed that a few of the project types that we had in 2010 are gone or different. The biggest difference for me right now is the removal of the Windows Installer project. Now we are being forced to use the InstallShield LE (Limited Edition). The problem here is that I write a ton of Windows Services and I can\'t see how to setup InstallShield LE. It appears that we (my company) will have to invest in licenses for

Starting a process with credentials from a Windows Service

两盒软妹~` 提交于 2019-11-26 06:41:54
问题 I have a Windows service that runs as mydomain\\userA. I want to be able to run arbitrary .exes from the service. Normally, I use Process.Start() and it works fine, but in some cases I want to run the executable as a different user (mydomain\\userB). If I change the ProcessStartInfo I use to start the process to include credentials, I start getting errors - either an error dialog box that says \"The application failed to initialize properly (0xc0000142). Click on OK to terminate the

Detecting USB drive insertion and removal using windows service and c#

為{幸葍}努か 提交于 2019-11-26 06:30:06
Looking into possibility of making an USB distributed application that will autostart on insertion of an USB stick and shutdown when removing the stick Will use .Net and C#. Looking for suggestion how to approach this using C#? Update: Two possible solutions implementing this as a service. - override WndProc or - using WMI query with ManagementEventWatcher You can use WMI, it is easy and it works a lot better than WndProc solution with services. Here is a simple example: using System.Management; ManagementEventWatcher watcher = new ManagementEventWatcher(); WqlEventQuery query = new

Am I Running as a Service

↘锁芯ラ 提交于 2019-11-26 05:58:18
问题 I am currently writing a little bootstrap code for a service that can be run in the console. It essentially boils down to calling the OnStart() method instead of using the ServiceBase to start and stop the service (because it doesn\'t run the application if it isn\'t installed as a service and makes debugging a nightmare). Right now I am using Debugger.IsAttached to determine if I should use ServiceBase.Run or [service].OnStart, but I know that isn\'t the best idea because some times end

Reading Excel Files as a Server Process

故事扮演 提交于 2019-11-26 05:38:20
问题 I\'m trying to find an appropriate way to read the contents of an Excel file on an NT server operating system. I have numerous problems using the Excel API and then came across the official Microsoft on Office Automation which states that the Excel API is not suitable for Excel automation. The sorts issues that I saw were similar to those described in the article. Is there another way that I can read an Excel file (xls, xlsx, xlsm) on a server (no UI) in such a way that doesn\'t suffer the