We have a server that is on the same LAN as my work computer. I know you can use "net stop" and "net start" in a batch file to restart a service on the local machine, but is it possible to do that for a remote machine?
I know you can use \computer to browse a networked machine, for example, so is there some syntax that would be something like \computer net stop service or so on?
Right now I have to Remote Desktop into the machine, restart the service, then log off, which is a hassle.
Create a Desktop shortcut
in the cmd to run enter :
sc \\server stop service
sc is the service management tool
server is your remote server name or IP
and finally service is the name of the service you target
I figured it out - for anyone else wondering: you can use this command:
C:\Windows\System32\runas.exe /savecred /user:[domain\user] "C:\windows\system32\cmd.exe /c C:\Test.bat" Where your batch file with the sc \server stop service is in C:\Test.bat. (You can move that around obviously)
Related
I need to stop and start IIS server for TFS build. When do this using .bat file iisreset /stop, similarly for start.
When I do this I get
Access denied, you must be an administrator of the remote computer to use this command. Either have your account added to the administrator local group of the remote computer or to the domain administrator global group.
Please note: This is Windows server 2019
I am already admin of this machine.
I have given read/write access to everyone in this folder.
I have unset EnableLUA to '0' in the registry as told in link for site
Above all these, I restarted machine.
I still get error in TFS build.
When you start a build in TFS the execution of that build is effectively done by a build agent. A build agent is just a service running on any particular machine. So, your batch file that shall start/stop the IIS service will be executed by whatever build agent is running your particular build.
This in terms means that your batch file is executed by the user that is used to run the build service. If that user does not have the necessary admin rights you face this particular error message.
What you need to do is make sure that all accounts that you use to run your build agents have administrative permissions on whatever machine you want to start/stop IIS.
You are trying to do IISRESET in your batch script. You need to be an Administrator as basic right to execute IISRESET command. So the account which the build is running needs to be part of the Admin group on the box.
Other approach is to stop and start w3svc using sc config commands or NET STOP WAS /Y and NET START W3SVC
Both of your answers are correct, I added the 'Network Service' of TFS to admin group of machine. Then build was success. Administrative tools>Computer Management> Local Users and Groups>Groups>
Inside Administrators and Users add 'Network Services'. If you don't find 'Network Service' then change location to your computer node and add them.
I would like to write a script and run it from my local PC to stop and start an application pool and site that exists on a server.
Value of App Pool and Site - Test
Value of server - SERVER1
Any guidance would be much appreciated.
Run Command Prompt with Administrative rights, and type the following:
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
or use the stop command. You could save this in a batch file, but it must be executed with higher privileges.
For the application pool on a remote server, you could use PsExec:
Psexec \\{Computer Name of ISS7 Server} C:\Windows\System32\inetsrv\appcmd recycle apppool my-app-pool
Is it possible to run JMeter server as a service in windows?
Currently I'm just logging in and running it manually, but from time to time I have to restart this machine and I would like to make JMeter server run automatically after each restart (even no user logs in after restart).
To create windows service sc create serviceName binpath= "path\to\exe"
You can also create a shortcut/bat file in the windows startup folder to start the JMeter. C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
You can also have a look at this - to start a program using windows task scheduler w/o user log in.
Unfortunately the SC command isn't available on W2000 yet, so I cannot use it.
I'm trying to check if a service is running or not on a W2000 server, and if it is not running the script should be able to start the service.
How to do this on Windows 2000?
net start | find "yourservice"
if %errorlevel%==1 net start "yourservice"
How do I uninstall a Windows Service when there is no executable for it left on the system? I can not run installutil -u since there is not executable left on the system. I can still see an entry for the service in the Services console.
The reason for this state is probably because of a problem in the msi package that does not remove the service correctly, but how do I fix it once the service is in this state?
You should be able to uninstall it using sc.exe (I think it is included in the Windows Resource Kit) by running the following in an "administrator" command prompt:
sc.exe delete <service name>
where <service name> is the name of the service itself as you see it in the service management console, not of the exe.
You can find sc.exe in the System folder and it needs Administrative privileges to run. More information in this Microsoft KB article.
Alternatively, you can directly call the DeleteService() api. That way is a little more complex, since you need to get a handle to the service control manager via OpenSCManager() and so on, but on the other hand it gives you more control over what is happening.
Remove Windows Service via Registry
Its very easy to remove a service from registry if you know the right path. Here is how I did that:
Run Regedit or Regedt32
Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
Look for the service that you want delete and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
Delete Windows Service via Command Window
Alternatively, you can also use command prompt and delete a service using following command:
sc delete
You can also create service by using following command
sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"
Note: You may have to reboot the system to get the list updated in service manager.
Here is the powershell script to delete a service foo
$foo= Get-WmiObject -Class Win32_Service -Filter "Name='foo'"
$foo.delete()
found here
I just tried on windows XP, it worked
local computer:
sc \\. delete [service-name]
Deleting services in Windows Server 2003
We can use sc.exe in the Windows Server 2003 to control services, create services and delete services. Since some people thought they must directly modify the registry to delete a service, I would like to share how to use sc.exe to delete a service without directly modifying the registry so that decreased the possibility for system failures.
To delete a service:
Click “start“ - “run“, and then enter “cmd“ to open Microsoft Command Console.
Enter command:
sc servername delete servicename
For instance, sc \\dc delete myservice
(Note: In this example, dc is my Domain Controller Server name, which is not the local machine, myservice is the name of the service I want to delete on the DC server.)
Below is the official help of all sc functions:
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
USAGE:
sc
My favourite way of doing this is to use Sysinternals Autoruns application. Just select the service and press delete.
I'd use PowerShell for this
Remove-Service -Name "TestService"
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-service
Create a copy of executables of same service and paste it on the same path of the existing service and then uninstall.