When entering commands, you should do so as Administrator. E.g. from Windows start menu, type in cmd
, right click on the cmd.exe
or Command Prompt
it gives you, and select Run as administrator
.
Install TomcatN as a service:
Just run tomcat's c:\path\to\TomcatN\bin\service.bat
and give it
a service name to use, i.e. Tomcat8
. Or,
sc Create TomcatN binPath= "c:\path\to\TomcatN\bin\tomcatN.exe" displayName= "Apache Tomcat N"
Set the service to run as a specific user:
Most of the time you don't need this. But sometimes you need to
access the Windows network as a registered user. For example, if you are taking advantage of some Active Directory functionality. It might work to use the following:
C:\path\to\tomcatN\bin\service.bat install TomcatN --user=George --password=abc123
But probably not. You can configure the service manually instead.
Manually configure the service to use a specific username and password:
From the Windows command prompt, you can use the services configurator.
Some commands of interest:
sc
sc query TomcatN
sc qc TomcatN
sc config TomcatN obj= "MyHostName\George" password= "abc123"
Take care to note the space that comes after the equal signs in that last command.
Ensure the user has permissions:
Enter the gpedit.msc
command. In the GUI that appears, navigate to
Local Computer Policy | ...
- Computer Configuration | ...
- Windows Settings | []Log on as a service
- Security Settings | ...
User Rights Assignment | ...
Double-click on Log on as a service
and Add User or Group...
. Type
the shorthand for the username you want the service to use into the field,
click Check Names
, and press OK.
Confirm that TomcatN is running as intended:
You can use the following commands to start, stop, and check the status of the service:
net start TomcatN
net stop TomcatN
sc query TomcatN
Checking that the login works as intended
Make sure you've started the service running. Open Windows Task Manager and view the Processes tab. Click on Show processes from all users
if necessary. TomcatN
should be listed, with the username you specified next to it.
Best Answer
I was getting the very same error and I managed to sort it out. Though in my case, even though the same error occurred on every start of the machine, the service was running, as I was able to use my app. But I seriously wanted to get rid of this problem so the client will not be forced to see this annoying error.
The way I did it was set up the tomcat7w.exe to always start as an administrator. Exactly you do it in the following way: right click on the tomcat7w.exe which is in the 'bin' folder of the tomcat installation, select 'Properties', then in 'Compatibility' tab under 'Privilege Level' select the 'Run this program as an administrator'.
I have put my answer for completeness as I think this might be the only way for Win 7 Home users, as in this version there is simply no option to set Local Policies which is required in the answer provided by @ta.speot.is (BTW +1)