Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Desktop shortcut to restart a windows service

Is it possible to create a windows desktop shortcut that will restart a windows service?

I'd like a button to restart my apache service after I have made changes to the config file.

like image 343
Jon Winstanley Avatar asked Jan 03 '10 18:01

Jon Winstanley


People also ask

What is the shortcut to open a service in Windows?

Press the Win + R keys on your keyboard, to open the Run window. Then, type "services. msc" and hit Enter or press OK. The Services app window is now open.

How do I create a desktop shortcut for services?

So I created a LNK shortcut which points to the batch script web_servers_start. cmd and checked "Run as administrator" in the file's Properties dialog under the "Advanced..." button on the Shortcut tab. You can place the LNK shortcut on the desktop, start menu or wherever you prefer.


2 Answers

You can do this in a batch file, then make a shortcut to it.

Create a text file with the following content, but save it with the file extension .bat

net stop "Service Name" net start "Service Name" 

Once the file exists, you can create a shortcut to it, and even assign a keyboard shortcut too if deemed necessary.

like image 105
Daniel A. White Avatar answered Oct 02 '22 16:10

Daniel A. White


You can accomplish this without a batch file using the following shortcut target:

C:\Windows\System32\cmd.exe /c "net stop "Service Name" & net start "Service Name"" 

In addition to the answer the following comment by Tibo is mandatory:

To make it run as Administrator (required for some services, maybe all?), in the shortcut's properties window, tab Shortcut, clic on the button "Advanced..." (at the bottom) then check "Run as administrator". It will open the User Account Control popup each time.

like image 39
Jason Avatar answered Oct 02 '22 17:10

Jason