Starting a user defined service in windows Xp - windows-services

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.

Related

Stopping OrientDB service fails, ETL import not possible

My goal is to import data from CSV-files into OrientDB.
I use the OrientDB 2.2.22 Docker image.
When I try to execute the /orientdb/bin/oetl.sh config.json script within Docker, I get the error: "Can not open storage it is acquired by other process".
I guess this is, because the OrientDB - service is still running. But, if I try to stop it i get the next error.
./orientdb.sh stop
./orientdb.sh: return: line 70: Illegal number: root
or
./orientdb.sh status
./orientdb.sh: return: line 89: Illegal number: root
The only way for to use the ./oetl.sh script is to stop the Docker instance and restart it in the interactive mode running the shell, but this is awkward because to use the "OrientDB Studio" I have to stop docker again and start it in the normal mode.
As Roberto Franchini mentioned above setting the dbURL parameter in the Loader to use a remote URL fixed the first issue "Can not open storage it is acquired by other process".
The issues with the .orientdb.sh still exists, but with the remote-URL approach I don't need to shutdown and restart the service anymore.

How do I install Tomcat service as Automatic (Delayed Start)?

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

make a jruby program a windows service

I have a JRuby program that I want to be a windows service. I have seen some things on creating a service with Ruby, but we don't want to install ruby on our client machines. It appears to be not supported in JRuby.
I created a dummy program to try this out:
path = "C:/tmp/my-svc.log"
if File.exists?(path)
File.open(path,"a"){|f| f.write(" called again\n")}
else
File.open(path,"w"){|f| f.write(" called first time\n")}
end
while true do
sleep 5
puts 'I am a service'
end
I did this:
Z:\play>sc.exe create "larz service 2.1" binpath= "C:\jruby-1.6.7.2\bin\jruby -S Z:\play\my-win-svc.rb" start= auto
[SC] CreateService SUCCESS
Trying to start it I got this error:
Z:\play>sc start "larz service 2.1"
[SC] StartService FAILED with error 193.
Z:\play>sc query "larz service 2.1"
SERVICE_NAME: larz service 2.1`
TYPE : 10 WIN32_OWN_PROCESS`
STATE : 1 STOPPED
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
I have seen alot of posts on the web on different ways to create windows services, using initsrv.exe, powershell, running CMD, editing the registry and so on, but I am not sure what is really going on or if I need to call some API. It doesn't appear as if the other approaches add any specific start parameters that I could tell. In addition, I added code at the beginning of my test service to write to a file in /tmp and the file is not being written so when I try to start the program, it never actually is being executed.
Thanks ..
Ok, so I got a little farther, but still mystified
Z:\play>sc config "larz service 2.2" obj= EEE\lgud password= "Ssssssss#"
[SC] ChangeServiceConfig SUCCESS
Z:\play>sc start "larz service 2.2"
[SC] StartService FAILED 1069:
the service did not start due to a logon failure.
It seems I entered the correct format for user/pw as at other times it errored out on the config command.
If you are positive that the password is correct, perhaps the user you have specified doesn't have the right privileges to run as a service. Try entering the account information on the Windows Services Application (services.msc) Log On tab, which will let you know if there is a problem with that user.
But beyond that, I don't see how you're going to get this going without Ruby installed. Your service's executable path is set to a .rb file -- what application do you expect Windows to launch to run that file, if not Ruby?

Unable to Delete or Create a Windows Service from the DOS Command Line

I am attempting to delete a C# based Windows Service from the DOS command line as follows:
sc Delete "MyService".
I am getting an error which says:
"[SC] OpenSCManager FAILED: 5"
"Access is Denied"
This is my own personal computer I'm attempting this on. Can anyone tell me exactly what I'm being denied from, and how to get around this?
You need to run this from an elevated command prompt (i.e. Run as Administrator), in order to ensure the correct permissions.
See how to do this in the answer to "How do I run a command with elevated privileges?" on the official Command Prompt: frequently asked questions page.

How can I delete a service in Windows?

I have a couple old services that I want to completely uninstall. How can I do this?
Use the SC command, like this (you need to be on a command prompt to execute the commands in this post):
SC STOP shortservicename
SC DELETE shortservicename
Note: You need to run the command prompt as an administrator, not just logged in as the administrator, but also with administrative rights. If you get errors above about not having the necessary access rights to stop and/or delete the service, run the command prompt as an administrator. You can do this by searching for the command prompt on your start menu and then right-clicking and selecting "Run as administrator". Note to PowerShell users: sc is aliased to set-content. So sc delete service will actually create a file called delete with the content service. To do this in Powershell, use sc.exe delete service instead
If you need to find the short service name of a service, use the following command to generate a text file containing a list of services and their statuses:
SC QUERY state= all >"C:\Service List.txt"
For a more concise list, execute this command:
SC QUERY state= all | FIND "_NAME"
The short service name will be listed just above the display name, like this:
SERVICE_NAME: MyService
DISPLAY_NAME: My Special Service
And thus to delete that service:
SC STOP MyService
SC DELETE MyService
Click Start | Run and type regedit in the Open: line. Click OK.
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Scroll down the left pane, locate the service name, right click it and select Delete.
Reboot the system.
As described above I executed:
sc delete ServiceName
However this didn't work as I was executing it from PowerShell.
When using PowerShell you must specify the full path to sc.exe because PowerShell has a default alias for sc assigning it to Set-Content. Since it's a valid command it doesn't actually show an error message.
To resolve this I executed it as follows:
C:\Windows\System32\sc.exe delete ServiceName
Use services.msc or (Start > Control Panel > Administrative Tools > Services) to find the service in question. Double-click to see the service name and the path to the executable.
Check the exe version information for a clue as to the owner of the service, and use Add/Remove programs to do a clean uninstall if possible.
Failing that, from the command prompt:
sc stop servicexyz
sc delete servicexyz
No restart should be required.
SC DELETE "service name"
Run the command on cmd as Administrator otherwise you will get this error :-
openservice failed 5 access is denied
If you have Windows Vista or above please run this from a command prompt as Administrator:
sc delete [your service name as shown in service.msc e.g moneytransfer]
For example: sc delete moneytransfer
Delete the folder C:\Program Files\BBRTL\moneytransfer\
Find moneytransfer registry keys and delete them:
HKEY_CLASSES_ROOT\Installer\Products\
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\EventLog\
HKEY_LOCAL_MACHINE\Software\Classes\Installer\Assemblies\ [remove .exe references]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Folders
These steps have been tested on Windows XP, Windows 7, Windows Vista, Windows Server 2003, and Windows Server 2008.
We can do it in two different ways
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.
If they are .NET created services you can use the installutil.exe with the /u switch
its in the .net framework folder like
C:\Windows\Microsoft.NET\Framework64\v2.0.50727
This did the job for me on Windows 10:
start the cmd.exe as admin
run SC DELETE "com.docker.service"
reinstall docker
Here is a vbs script that was passed down to me:
Set servicelist = GetObject("winmgmts:").InstancesOf ("Win32_Service")
for each service in servicelist
sname = lcase(service.name)
If sname = "NameOfMyService" Then
msgbox(sname)
service.delete ' the internal name of your service
end if
next
sc delete name
Before removing the service you should review the dependencies.
You can check it:
Open services.msc and find the service name, switch to the "Dependencies" tab.
Source: http://www.sysadmit.com/2016/03/windows-eliminar-un-servicio.html
You can use my small service list editor utility Service Manager
You can choose any service > Modify > Delete. Method works immediately, no reboot required.
Executable file: [Download]
Source code: [Download]
Blog post: [BlogLink]
Service editor class: WinServiceUtils.cs
For me my service that I created had to be uninstalled in Control Panel > Programs and Features

Resources