EzDevInfo.com

windows-services interview questions

Top windows-services frequently asked interview questions

Create Windows service from executable

Is there any quick way to, given an executable file, create a Windows service that, when started, launches it?


Source: (StackOverflow)

Modifying the "Path to executable" of a windows service

I'd like to modify the path to my application, but doing so breaks it because the service still points to the old location.

By going to Administrative Tools > Services you can open a properties dialog and view the Path to executable, but there is no way to change it.

Is there any way a user can modify the service path without having to reinstall the application ?


Source: (StackOverflow)

Advertisements

Check if a Windows service exists and delete in PowerShell

I am currently writing a deployment script that installs a number of Windows services.

The services names are versioned, so I want to delete the prior Windows service version as part of the installs of the new service.

How can I best do this in PowerShell?


Source: (StackOverflow)

How to install a windows service programmatically in C#?

I have 3 projects in my VS solution. 1 is a web app, the other is a windows service and the last one a setup project for my web app.

What i want is by the end of the installation of the web app in my setup project, within my custom action to try and install my windows service given that i have the location of the assembly by then.

Thanks for all the help in advance.


Source: (StackOverflow)

Run batch file as a Windows service [closed]

In order to run one application, a batch file has to be kicked off (which does things like start Jetty, display live logs, etc). The application will work only if this batch file is running. I am hence forced to have this batch file running and not logout from the Windows server.

Can this batch file be run as a service? I am experimenting with one of the suggestions from a similar question.


Source: (StackOverflow)

How can a windows service programmatically restart itself?

I need to write robust code in .NET to enable a windows service (server 2003) to restart itself. What is the best way to so this? Is there some .NET API to do it?


Source: (StackOverflow)

Start / Stop a Windows Service from a non-Administrator user account

I have a WindowsService named, say, BST. And I need to give a non-Administrator user, UserA, the permissions to Start/Stop this particular service. My service runs on a variety of Windows OS, starting from Windows Server 2003 to Windows 7.

How can I do this?

I Googled and found some stuff about giving permissions using the command [sc sdset], but I am not exactly sure about the parameters. I do not want to set the permissions for a group, but ONLY to a particular user, UserA in this case.


Source: (StackOverflow)

How do I uninstall a Windows service if the files do not exist anymore?

How do I uninstall a .NET Windows Service, if the service files does not exists anymore?

I installed a .NET Windows Service using InstallUtil. I have since deleted the files but forgot to run

 InstallUtil /u

first. So the service is still listed in the Services MMC.

Do I have to go into the registry? Or is there a better way?


Source: (StackOverflow)

Easier way to debug a C# Windows Service

Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It's kind of cumbersome and I'm wondering if there is a more straightforward approach.


Source: (StackOverflow)

Map a network drive to be used by a service

Suppose some Windows service uses code that wants mapped network drives and no UNC paths. How can I make the drive mapping available to the service's session when the service is started? Logging in as the service user and creating a persistent mapping will not establish the mapping in the context of the actual service.


Source: (StackOverflow)

How to create an installer for a .net Windows Service using Visual Studio

How do I create an installer for a Windows Service that I have created using Visual Studio?


Source: (StackOverflow)

windows service vs scheduled task

What are the cons and pros of windows services vs scheduled tasks for running a program repeatedly (e.g. every two minutes)?


Source: (StackOverflow)

Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

I developed a Windows service using C#.NET to generate PDF report. To generate PDF file I am using a third party dll. The application is running in my Windows XP platform. When I deployed the service in Windows Server 2008 64 bit version, I got this error:

Retrieving the COM class factory for component with CLSID {46521B1F-0A5B-4871-A4C2-FD5C9276F4C6} failed due to the following error: 80040154.

I registered the DLL using the regsvr32 command. I able to see this CLSID in the registry. But the problem persists.

What could be the problem?


Source: (StackOverflow)

How do you run CMD.exe under the Local System Account?

I'm currently running Vista and I would like to manually complete the same operations as my Windows Service. Since the Windows Service is running under the Local System Account, I would like to emulate this same behavior. Basically, I would like to run CMD.EXE under the Local System Account.

I found information online which suggests lauching the CMD.exe using the DOS Task Scheduler AT command, but I received a Vista warning that "due to security enhancements, this task will run at the time excepted but not interactively." Here's a sample command:

AT 12:00 /interactive cmd.exe

Another solution suggested creating a secondary Windows Service via the Service Control (sc.exe) which merely launches CMD.exe.

C:\sc create RunCMDAsLSA binpath= "cmd" type=own type=interact
C:\sc start RunCMDAsLSA

In this case the service fails to start and results it the following error message:

FAILED 1053: The service did not respond to the start or control request in a timely fashion.

The third suggestion was to launch CMD.exe via a Scheduled Task. Though you may run scheduled tasks under various accounts, I don't believe the Local System Account is one of them.

I've tried using the Runas as well, but think I'm running into the same restriction as found when running a scheduled task.

Thus far, each of my attempts have ended in failure. Any suggestions?


Source: (StackOverflow)

Install Windows Service created in Visual Studio

When I create a new Windows Service in Visual Studio 2010, I get the message stating to use InstallUtil and net start to run the service.

I have tried the following steps:

  1. Create new project File -> New -> Project -> Windows Service
  2. Project Name: TestService
  3. Build project as is (Service1 constructor, OnStart, OnStop)
  4. Open command prompt, run "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" TestService.exe
  5. Run net start TestService.

Output of step 4

Running a transacted installation.

Beginning the Install phase of the installation.

See the contents of the log file for the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio 2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

Installing assembly 'C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe assembly.

The Install phase completed successfully, and the Commit phase is beginning.

See the contents of the log file for the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe assembly's progress.

The file is located at C:\Users\myusername\Documents\Visual Studio 2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

Committing assembly 'C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

Affected parameters are:

logtoconsole =

logfile = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

assemblypath = C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe assembly.

Remove InstallState file because there are no installers.

The Commit phase completed successfully.

The transacted install has completed.

Output of step 5

The service name is invalid.

More help is available by typing NET HELPMSG 2185.


Source: (StackOverflow)