I created an installer with install4j that calls the provided Tomcat service.bat file to create a Windows service.
That works fine, but is there anyway to modify the service.bat so by default the installed service is Automatic (Delayed Start) as opposed to Automatic or Manual?
According to this page:
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
The --Startup parameter takes either auto or manual with a default of manual if left empty. I'm a little confused because I left it out and my services are set to Automatic after installation, which contradicts that page.
Doesn't seem like a parameter for Automatic (Delayed Start) is supported so I ended up simply calling a .bat file after the service is installed. It sets the appropriate key/value in the Windows registry to mark a service as delayed-start.
reg add "HKLM\SYSTEM\CurrentControlSet\services\%1" /v DelayedAutostart /t REG_DWORD /d 0x1 /f"
Just run the batch file, passing an argument for the service name.
automaticDelayedStart.bat MyService
You can also write a batch script as below:
rem :To create service with name TestTomcat
call service.bat install TestTomcat
rem :To set tomcat service as a startup service and also set heap size.
call tomcat7 //US//TestTomcat --Startup=auto ++JvmOptions=-Xmx2048m
rem :To start service
call sc start TestTomcat
And from installer you can run this batch file using "Run executable or file" action.
Thanks
-Satish Lakhani
I'm using Memcached-for-Windows, see:
http://blog.elijaa.org/index.php?post/2010/08/25/Memcached-1.4.5-for-Windows&similar
I've tried to use:
sc create "memcached" binPath="C:/memcached/mem
cached.exe" start=auto
but I can't create the Windows service, and no warning or error, just:
Creates a service entry in the registry and Service Database.
SYNTAX:
sc create [service name] [binPath= ] <option1> <option2>...
CREATE OPTIONS:
NOTE: The option name includes the equal sign.
type= <own|share|interact|kernel|filesys|rec>
(default = own)
start= <boot|system|auto|demand|disabled>
(default = demand)
error= <normal|severe|critical|ignore>
(default = normal)
binPath= <BinaryPathName>
group= <LoadOrderGroup>
tag= <yes|no>
depend= <Dependencies(separated by / (forward slash))>
obj= <AccountName|ObjectName>
(default = LocalSystem)
DisplayName= <display name>
password= <password>
To implement this, you can even execute a command line, which inturn creates a service.
First go to the path where the .exe file exists through command line.
C:\Users\sireesh.yarlagadda>memcached.exe -d install
After executing this line, you will be seeing a new service created for memcached
The reason you're getting an error is that there must be a space after the binPath= . This is a very annoying 'feature' of sc. Also you'd need a space after the start=.
sc create "memcached" binPath= "C:/memcached/memcached.exe" start= auto
The above command wouldn't give you the syntax error. However, I suspect memcached still won't run successfully as a service.
memcached isn't a native Windows Service so you must use a "service wrapper" program to add the missing functionality. Microsoft's free Srvany utility should do the trick but several commercial alternatives are also available.
(Note that some Windows ports of memcached support the "-d" flag to automatically install and manipulate memcached as a native Windows Service but that doesn't seem to be available in NorthScale's version...)
You can build Memcached on Windows.
http://vasil9v.tumblr.com/post/31921755331/compiling-memcached-on-cygwin-windows
I want to install a Windows service using a Windows command prompt (not the Visual Studio command prompt).
How do I do this?
Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe"
Regarding a comment, for 64bit apps, use below:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe
Nothing wrong with SC Create command.
Just you need to know the correct args :
SC CREATE "MySVC" binpath= "D:\Me\Services\MySVC\MySVC.exe"
If the directory's name has a space like c:\program files\abc 123, then you must use double quotes around the path.
installutil.exe "c:\program files\abc 123\myservice.exe"
It makes things much easier if you set up a bat file like following,
e.g. To install a service, create a "myserviceinstaller.bat" and "Run as Administrator"
#echo off
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
installutil.exe "C:\Services\myservice.exe"
if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem
pause
to uninstall service,
Just add a -u to the installutil command.
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "C:\Services\myservice.exe"
Perform the following:
Start up the command prompt (CMD) with administrator rights.
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
Press return and that's that!
It's important to open with administrator rights otherwise you may find errors that come up that don't make sense. If you get any, check you've opened it with admin rights first!
To open with admin rights, right click 'Command Prompt' and select 'Run as administrator'.
Source:
http://coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/
Install Service:-
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe"
"C:\Services\myservice.exe"
UnInstall Sevice:-
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" -u "C:\Services\myservice.Service.exe"
Create a *.bat file beside of your windows service exe file for installing with the following context:
CLS
ECHO Installing My Windows Service
START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe "%~d0%~p0\YourWindowsServiceExeName.exe"
Create a *.bat file beside of your windows service exe file for uninstalling with the following context:
CLS
ECHO Uninstalling My Windows Service
START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "%~d0%~p0\YourWindowsServiceExeName.exe"
Run each of bat file as Admin to install or uninstall your windows service.
I must add one more point in this thread. To install/uninstall 64-bit version of assemblies one should use 64-bit version of tool. To install a service, the command should be:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe"
"C:\YourFolder\YourService.exe"
and to uninstall the command should be:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" -u
"C:\YourFolder\YourService.exe"
Run Windows Command Prompt as Administrator
paste this code: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\ to go to folder
edit and run this too: installutil C:\ProjectFolder\bin\Debug\MyProject.exe
Note: To uninstall: installutil /u C:\ProjectFolder\bin\Debug\MyProject.exe
open Developer command prompt as Admin and navigate to
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Now use path where is your .exe there
InstallUtil "D:\backup\WindowsService\WindowsService1\WindowsService1\obj\Debug\TestService.exe"
Open Visual studio and select new project by selecting Windows Service template in Windows Desktop tab. Than copy following code into your service_name.cs file.
using System.Diagnostics;
using System.ServiceProcess;
namespace TimerService
{
public partial class Timer_Service : ServiceBase
{
public Timer_Service()
{
InitializeComponent();
}
static void Main()
{
if (System.Diagnostics.Debugger.IsAttached)
{
Timer_Service service = new Timer_Service();
service.OnStart(null);
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Timer_Service()
};
ServiceBase.Run(ServicesToRun);
}
}
protected override void OnStart(string[] args)
{
EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service start successfully." });
}
protected override void OnStop()
{
EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service stop successfully." });
}
}
}
Right-Click on service_name.cs file and open designer of service. than right-click and select Add Installer. than right-click on serviceProcessInstaller1 and change its property value of Account from User to Local System.
Remove static void main method from Program.cs file.
Than save and Build your project.
NOTE: goto bin\Ddebug folder of your project folder. Than open Properties of your service_name.exe file. Than goto Compatibility tab. Than click on Change Settings For All Users.
Select option Run this program as an administrator.
Now, You have to open CommandPromt as Administrator.
After open, set directory to where your InstallUtil.exe file is placed.
for ex: C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
now write the following command:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe -i C:\TimerService\TimerService\bin\Debug\TimerService.exe
Note: -i is for install he service and -u for Unsinstall.
after -i set the write the path where you want to install your service.
now write the command in CommandPromt as follows:
C:\TimerService\TimerService\bin\Debug>net start service_name
Note: use stop for stop the Service.
Now, open ViewEventLog.exe. Select Windows Logs>Application. There you can check your Service's log by start and stop the service.
the following code , install and uninstall the Service,
Open the command prompt and run the program as an administrator and fire the below command and press enter.
Syntax
To Install
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe + Your copied path + \your service name + .exe
eg :Our Path
InstallUtil.exe C:\MyFirstService\bin\Debug\MyFirstService.exe
To uninstall
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe -u + Your copied path + \your service name + .exe
eg : Our path InstallUtil.exe -u C:\MyFirstService\bin\Debug\MyFirstService.exe
for more help you can see the following link: sample program
If you are using Powershell and you want to install .NET service you can use Install-Service module. It is a wrapper for InstalUtil tool.
It exposes 3 commands
Install-Service - invokesĀ InstallUtil.exe pathToExecutable command
Install-ServiceIfNotInstalled - first it checks if service is
installed if not perform the method Install-Service
Uninstall-Service- it uninstalls service. ServiceName of path to executable can be used.
Code to this module can be viewed here
start up the command prompt (CMD) with administrator rights.
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
Press return
1.From the Start menu, select the Visual Studio directory, then select Developer Command Prompt for VS .
2.The Developer Command Prompt for Visual Studio appears.
3.Access the directory where your project's compiled executable file is located.
4.Run InstallUtil.exe from the command prompt with your project's executable as a parameter
when your assembly version and your Visual studio project Biuld setting on dot net 2 or 4 install with same version.
install service with installutil that same version
if build in dot net 4
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe
if build in dot net 2
Type c:\windows\microsoft.net\framework\v2.0.11319\installutil.exe
Follow these steps when deploying the Windows Service, don't lose time:
Run command prompt by the Admin right
Insure about release mode when compilling in your IDE
Give a type to your project installer on design view
Select authentication type in accordance the case
Insure about software dependencies: If you are using a certificate install it correctly
Go your console write this:
C:\Windows\Microsoft.NET\Framework\yourRecentVersion\installutil.exe c:\yourservice.exe
there is a hidden -i argument before the exe path -i c:\ you can use -u for uninstallling
Look your .exe path to seem log file. You can use event viewer to observing in the feature
you can do using command prompt and write:
C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i ".EXE file of window service"
You can use InstallUtil to install any windows service.
1: C:\Windows\Microsoft.NET\Framework64\v4.0.30319 in command prompt running as Adminstrator.
2: Copy the Exe path and type InstallUtil.exe "your exe path"
and hit enter.
If you want visual elaboration. Goto below link.
It helped me alot.
https://youtu.be/yrdyYxzI7SE
You should open command prompt, go to
C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i ".EXE file of window service"
Open command prompt as administrator, go to your Folder where your .exe resides.
To Install Exe as service
D:\YourFolderName\YourExeName /i
To uninstall use /u.
I am creating a user defined service on Windows Xp using sc.exe
To create I started with
sc.exe create "My Service" binPath= "D:\Service.bat"
Got a message CreateService SUCCESS.
Then I entered services.msc in the RUN and found the service which I created was there
Right clicked My Service then properties and when I started
I get an error as
ERROR 1053: The service did not respond to the start in a timely fashion
How do I fix this error.
Thanks
I think you need to enter cmd as command;
sc.exe create "My Service" binPath= "cmd /c D:\Service.bat"
And make sure the batch file does not stop too quick. At the first line of the batchfile let it write to a logfile, so you can see it is being executed. (and use a location where the service user may write to).
echo starting at %date% %time% > d:\service.log
As an alternative you can also use srvany.exe, see KB137890, but that is more hassle.
Problem
I am trying to install hudson build server on a windows server through remote desktop connection. I path to the Hudson folder in the C:\Hudson. The Hudson directory contains a folder called Home and the hudson.war file.
I tried to start it up using the following commands:
set JAVA_HOME=C:\Java\jdk1.6.0_20
set HUDSON_HOME=C:\Hudson\Home
java -jar C:\Hudson\hudson.war
Then I can navigate to http://localhost:8080 in internet explorer.
Question
When I try to use the Install as Windows Service function on the web interface, I get this error:
Installing a service
[Home] $ C:\Hudson\Home\hudson.exe install
WMI.WmiException: AccessDenied
at WMI.WmiRoot.BaseHandler.CheckError(ManagementBaseObject result)
at WMI.WmiRoot.ClassHandler.Invoke(Object proxy, MethodInfo method, Object[] args)
at WMI.Win32ServicesProxy.Create(String , String , String , ServiceType , ErrorControl , StartMode , Boolean , String[] )
at winsw.WrapperService.Run(String[] args)
at winsw.WrapperService.Main(String[] args)`
Why can't I install as a windows service and how can I fix this issue?
Answer
Found the solution.
When running the commands you need to open the command prompt by right clicking and selecting "run as administrator".
On the windows command prompt, execute: sc delete hudson
and for jenkins user, execute: sc delete jenkins
and then run install windows as a service.
Hope it helps :)
Try turning off User Account Control; that's what fixed it for me. Start > Run > UAC, then drag the dial to the lowest setting: "Never notify". May require a reboot.