How can I start and stop services on a remote machine? - windows

I have a requirement in the project such that we have to stop a specific service say "x" in a remote machine (which is on the same LAN), change the registry key remotely and start the service again.
I tried the command sc \server stop service, but I got the error:
[SC] GetServiceKeyName FAILED 1060:
The specified service does not exist as an installed service.
I am using Windows 2003 SP1. Are there any built in commands or APIs that are available on Windows?
I need the commmand to run on the command prompt.

Also keep in mind that the "service name" argument expected by the "sc" command line tool doesn't always equate to the name you see within the services control panel applet (which is the service "display name").
For example, the service that as appears "Adobe Acrobat Update Service" in my services control panel applet has an actual name of "AdobeARMservice". You must use the latter, but not the former, when managing the service through the "sc" utility.
Example:
sc Stop "AdobeARMservice" (works)
sc Stop "Adobe Acrobat Update Service" (doesn't work)
To get the "real" name of a service, double-click its entry in the service control panel applet and see the "service name" field on the General tab.
Of course in some cases, the display name and the service name are the same.

You may want to look into PSTools from SysInternals. Those tools are freely available and can help you manage processes on a remote Windows machine.
The tools included in the PsTools suite, which are downloadable as a package, are:
PsExec - execute processes remotely
PsFile - shows files opened remotely
PsGetSid - display the SID of a computer or a user
PsInfo - list information about a system
PsKill - kill processes by name or process ID
PsList - list detailed information about processes
PsLoggedOn - see who's logged on locally and via resource sharing
PsLogList - dump event log records
PsPasswd - changes account passwords
PsService - view and control services
PsShutdown - shuts down and optionally reboots a computer
PsSuspend - suspends processes
PsUptime - shows you how long a system has been running since its last reboot

From this URL:
To stop a service remotely you can use the command sc.
Example:
> sc \\computer stop "Service Name"
> sc \\computer start "Service Name"
Perhaps you are missing a "\" character?

Use OpenCSManager, then OpenService, then StartService.

Related

VS 2015 Remote debugging (msvsmon.exe) how to know which w3wp process attaches to which iis service

I am trying to remote debug web application by using Remote debugger (msvsmon.exe)
I am connecting ok and can see processes problem is server is running multiple applications and I am not sure which one to attach debugger to. One that I am trying to debug is not listed in IIS APPPOOL\... (should it be?) which I have hidden from screencap.
How can I tell which process to attach to?
1. If you have RDC (Remote Desktop Connection) to the server machine, then in IIS Manager (Internet Information Services Manager) you can see which ones are Network Services and which ones are Local Services.
I was lucky to get one that was Local Services which I had only one running on that server...
2. user friendly way
On the server go to IIS Manager -> Worker Procesess -> then you can match IDs to the IDs in attach to debugger window in Visual Studio...
3. Another way that can give you some insight is to use IDs of processes - IDs in your VS attach to process window can be matched to remote machine IDs (they are also in Task Manager on the server...)
To match ID to application pools on server run Command Prompt - As Administrator and run from %windir%\system32\intesrv\ folder command - appcmd list wp to get process ID to application pool mapping, this might help to narrow it down....
When you know which app pool which process is running, you can map them to applications that are running on that app pool in IIS Manager and pray that they will be one-to-one application to pool...
I know this is old but I ran into this because I was researching something relative.
Although you should be able to identify the process by the UserName column. You should go onto the server and identify the app pool your app is running under. Then you can look for that App Pool name in the UserName column.
On the other hand, you can go onto your server and follow the instructions below to get a full list.
Go to C:\Windows\System32\inetsrv\ in your windows explorer. Enter the command “appcmd.exe list wp”. It will list all the process associated with the Application Pools.

Unable to control Windows service created with sc

I created a Windows service for my application using a batch file containing the instruction:
sc create <name> binPath= "C:\my\path\" DisplayName= "MyName"
The service is created successfully and the application runs without issues. The Windows Service Manager shows the service in the list, however it does not have the "started" status, even though it is running. Clicking on "start service" fails with "Error 1053: The service did not respond to the start or control request in a timely fashion".
When attempting to control the service using the net command, such as
net stop <name>
or
net start <name>
these commands fail with similar error messages.
This happens consistently on all Windows I tested on (up to Windows 7). Restarting the machine does not change anything.
Any reason why a successfully created and running service cannot be started or stopped (or even have its status recognized)?
(Including information from comments to the question.)
Linux daemon processes are controlled through signals.
Windows Services have a completely model. The process needs to connect to the Service Control Manager (SCM: the services.exe process) on start up to provide a callback. This callback is the main entry to the service, and also how the SCM signals important events (eg. that the service should stop).
This is covered on MSDN, and .NET has specific support (by subclassing ServiceBase.)
It maybe possible to find a helper program that provides the SCM integration and launches you program, but likely it will just terminate your processes (*nix style signals do not exist on Windows) on the SCM sending a stop.

IIS w3svc error

I am trying to start my website in IIS, whenever I try to start my website I get the following error
Cannot start service w3svc on computer
I tried to start "World wide web publishing service", but I was unable to start it as it said:
Error 1068: The dependency service or group failed to start
Meanwhile when I checked my log I found this error,
The World Wide Web Publishing Service service depends on the HTTP service which failed to start because of the following error:
The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
Please help me, I am badly caught with this error, I have spent a week researching this error but haven't found a solution yet.
Confirm that "Windows Management Instrumentation" is started and its start up type is set to automatic.
Also make sure the following dependency services are started for World Wide Web Publishing Service:
Windows Process Activation Service
Remote Procedure Call (RPC)
DCOM Server Process Launcher
RPC Endpoint Mapper.
Open regedit, navigate to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP]:
a) Double click on Start and change value data from 4(disabled) to 3(automatically).
b) Delete "NoRun" key if this key exists.
(warning: backup any IIS website configuration first). UN-install "Internet information Service" and "Windows process activation service(if it is already installed)" from "Turn windows feature on or off" and Restart your PC.
Type the below command in CMD and press enter:
net start http
Now it will notify you that service is already running.
Re-install Internet information Service from "Turn windows feature on or off".
Start IIS and my websites are started now, no more "w3svc service is not running error."
As for me - I just restarted the computer.
Make sure these 2 services running and their startup type is automatic.If they disabled and not running right click on them and go to properties and change from there.
Windows process activation service
Worldwide web publishing service.
Run cmd as administrator. Type iisreset. That's it.
Go to Task Manager --> Processes and manually stop the W3SVC process. After doing this the process should start normally when restarting IIS
In my case it was C:\Windows\System32\inetsrv\config\applicationHost.config which had an issue.
I had a "system.web" section in this file which was causing the problem. Removed the section and everything started working
I have got same issue on my server. Follow below steps -
Open command prompt (run as administrator)
type IISReset and enter.
It works and solved my problem.
I have had this problem after a windows update. Windows Process Activation Service is dependent service for W3SVC. First, make sure that Windows Process Activation Service is running. In my case, it was not running and when I tried to run it manually, I got below error.
Windows Process Activation Service Error 2: The system cannot find the file specified
The issue seems to be, that windows adds an incorrect parameter to the WAS service startup parameters. I fixed the issue using the following steps:
Start regedit (just type it into start) Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WAS\Parameters
Delete the NanoSetup variable. This variable is preventing WAS from starting
Start the WAS service using task manager
Now start the W3SVC service
You can now start your website in IIS again
I found above WPA service solution in this stack overflow thread.
In my case, IIS suddenly stopped working, and after that Windows process activation service was unable to restart.
The solution to fix this was:
Find WAS service in the services tab of windows task manager
In context menu choose Go to process
Kill process (its name will be svchost.exe)
Restart Windows process activation service
My Net.Tcp Port Sharing Service was disabled. I changed its startup to manual, started the service, and then IISRESET worked.
I also verified that the following dependent services were started in Services ([windows]+[r] services.msc):
World Wide Web Publishing Service
Windows Process Activation Service
Remote Procedure Call (RPC)
DCOM Server Process Launcher
RPC Endpoint Mapper
Net.Msmq Listener Adapter
Net.Pipe Listener Adapter
Net.Tcp Listener Adapter
Net.Tcp Port Sharing Service
I found this solution by going through all dependencies and child dependencies of the World Wide Web Publishing Service and making sure that each service was enabled and started.
To verify all services for yourself, do the following:
Open up Services (just search for it from the start menu in Windows 10)
Find the World Wide Web Publishing Service
Right click on the service and then click "Properties"
Click on the Dependencies tab
Go through each system component in the two boxes and verify that each service is started (in Services).
Repeat steps 3-5 for each of the dependencies' dependencies until you run out of child dependencies
Service Properties - Dependencies Tab
This is probably a rarer case, but...
If you are using a custom AppPool Identity configuration be sure to check the AppPool is running. It may be turned off because credentials are invalid (usually due to an expired password). Update your credentials and start the AppPool.
I am able to resolve this by simply executing the below command in PowerShell to kill/stop service and restart the IIS server
taskkill /F /FI "SERVICES eq w3svc"
I managed to solve after:
Ctrl+Shift+Esc = To open Task Manager
In the "Processes" tab locate the "IIS Worker Process" and
finish it!
Run on cmd as an administrator. Type iisreset.
I was getting this error. It turns out World Wide Web Publishing Service was disabled.
Click Start, type Services in the Search box, and then click Services.
Scroll until you find the World Wide Web Publishing Service that is stopped or disabled.
right-click the service, and then click Properties.
Click the Startup type list, and then click Automatic.
Click Apply, and then click OK.

Scheduled Task for script vs Direct Execute: issues

I have a VBscript file which connects to remote computers over our network and initiates a WBEM-Scripting method. I can open a CMD console using the credentials for a domain user account which has local admin rights on all of our desktop computers, and the script performs as desired.
I created a scheduled task on a Windows Server 2003 member server which runs the same script file using the same credentials, but it fails to connect to the WMI provider on remote computers.
The desktops are all Windows 7 SP1 and the domain is Windows Server 2008 level (forest and domain).
The domain user account was added to the local administrators group on the server, and was granted "Logon as a service" rights via Group Policy.
Question: Is there something else I'm missing that could be causing the scheduled task to fail while the interactive execution works fine?
I've had this same problem happening (scripts do not run as schedule tasks but, executable files do). You can get around this by doing the following:
There is a Start in (Optional) text box below the Program/Script text box on the property page for the Actions Tab. Fill it to include the path of your script So if your script is at c:\users\user\desktop\script.vbs, the text boxes will look like this:
Program/Script:
c:\users\user\desktop\script.vbs
Add Arguments (Optional)
Start in (Optional) c:\users\user\desktop

Trouble with running myprogram.exe as service on windows 2008

The MyProgram.exe is made to listen the request from pipe and using command prompt its working perfect but I tried to work it by using windows service but not success I have tried following steps on windows server 2008 enterprise:
> sc create MyService binPath= "C:\test\MyProgram.exe" DisplayName= "MyProgramService"
>[SC] CreateService SUCCESS
>sc start MyService
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
reference
So I read on one blog that we need to create registry entry for the same then I tried the following steps
I found my newly created service under: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MyService
Click the key named MyService (it looks like a folder) from the menu in regedit. Select “edit” and “new” and then select “key.” This will create a new key which you should name “Parameters.” Next, right- click on the key that you just named “Parameters” and select “new” and then “string value.” Name the value “Application.” Double-click the string value and a box will pop up. In the box under “value data”, you need to put the full path to the Dropbox. In my case, the path was: C:\test\MyProgram.exe\MyProgram.exe
Start your new service. Navigate to the services list in the control panel‘s administrative tools or simply type services.msc in the run box. Find DropBox in the list and start it. New services should be set to start automatically, but feel free to check it to be sure.
But the service start for a few seconds and get terminated. When I start manually service from services.msc it give error
StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
Not sure why any one have work on it, please guidance to make it as service.
You can't run just any EXE as a Windows service. You must have an exe which understands what it means to be a service and which communicates appropriately with the Windows Service Control Manager.
Refer to the Microsoft documentation, starting with http://msdn.microsoft.com/en-us/library/windows/desktop/ms686953(v=vs.85).aspx.

Resources