How to communicate with a windows service?

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 () //constructor, to create your log repository { InitializeComponent(); if (!System.Diagnostics.EventLog.SourceExists(“YOURSource”)) { System.Diagnostics.EventLog.CreateEventSource( “YOURSource”, “YOURLog”); } eventLog1.Source = “YOURSource”; eventLog1.Log = “YOURLog”; } Now, implement: protected override … Read more

How do I change the name of my Windows service?

You might have added an installer by right clicking the design view of your Windows service class. If you have done this then you will find a ProjectInstaller class within your WindowsService project. By selecting this ProjectInstaller class you will find two installers on its design view -> 1.ServiceInstaller1 2.ServiceProcessInstaller1 Right click the ServiceInstaller1 and … Read more

Attaching Visual Studio debugger to Windows service — “attach” greyed out

I usually have the same issue and I take care of it by adding a boolean to my configuration that triggers a debug launch. You can launch a Visual Studio debugger instance that attaches to your Windows service process by calling this: System.Diagnostics.Debugger.Launch(); What’s nice is that you can call it wherever you wish in … Read more

How to send a custom command to a .NET windows Service from .NET code?

You can send “commands” to a service using ServiceController.ExecuteCommand: const int SmartRestart = 222; var service = new System.ServiceProcess.ServiceController(“MyService”); service.ExecuteCommand(SmartRestart); service.WaitForStatus(ServiceControllerStatus.Running, timeout); You’ll need to add a Reference to the System.ServiceProcess.dll assembly. The service can react to the command by overriding ServiceBase.OnCustomCommand: protected override void OnCustomCommand(int command) { if (command == SmartRestart) { // … … Read more

Install windows service without InstallUtil.exe

I know it is a very old question, but better update it with new information. You can install service by using sc command: InstallService.bat: @echo OFF echo Stopping old service version… net stop “[YOUR SERVICE NAME]” echo Uninstalling old service version… sc delete “[YOUR SERVICE NAME]” echo Installing service… rem DO NOT remove the space … Read more

How can a Windows Service determine its ServiceName?

From: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=387024 Here is a WMI solution. Overriding the ServiceBase.ServiceMainCallback() might also work, but this seems to work for me… protected String GetServiceName() { // Calling System.ServiceProcess.ServiceBase::ServiceNamea allways returns // an empty string, // see https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=387024 // So we have to do some more work to find out our service name, this only works if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)