Windows program doesn't run when started using sc create - c++

I have created a program which is supposed to run as Windows service, starting automatically on boot.
Also i have created a starter, which should create a service and then stop.
Starter is ran as administrator.
I call this system command from a starter:
system("sc create MyApp binpath= /*full path*/ type= own start= auto DisplayName= MyService");
system("sc start MyApp");
Then Windows says that service creation successful.
However, the program which should run as service just doesn't start!
After the "sc start" command the console shows nothing for a while, Task Manager shows "Starting", and later console says
"Error 1053: The service did not respond to the start or control request in a timely fashion".
I tried running a command like this, showed in another post here on StackOverflow:
sc create SERVICENAME binPath= "**cmd /c** c:\programlocation\program.exe"
However, then it says:
StartService Failed 2: The system cannot find the file specified.
So the **cmd /c** thingy doesnt work.
How to make it work, and please only Windows native tools, no external programs.

You could do something like this:
Native C++ Windows Service
But I'd switch to C++/CLI and port the following code examples from C#:
System.ServiceProcess.ServiceProcessInstaller
Or, even better yet, just do the Windows Service part of your code in C# ... it's much easier than rolling your own in C++.

Related

Can I run a process from my process without becoming its parent?

I have a somewhat strange request. Let me explain. I recently run into an issue when I needed to display my screensaver's configuration window by running the following command:
"C:\Windows\System32\mysvr.scr" /c
The problem is that my parent GUI application that calls it runs with High Mandatory Integrity Level, or S-1-16-12288, and due to this, when I run the following command via CreateProcess API the screensaver configuration (evidently?) tries to communicate with my app and fails because of its high integrity level.
So I'm trying to bypass this by having some other process run this command for me. I looked into possibly using RunDll32 but I don't know an API that I can use through it to start a process.
Any ideas?

Windows store app automating testing, run and detect when the application is stopped (suspended) c++

Im using this guide "automating the testing of windows 8 apps" to test my windows store app
http://blogs.msdn.com/b/windowsappdev/archive/2012/09/04/automating-the-testing-of-windows-8-apps.aspx
Unfortunaltely Ive run into a problem, I need to know when my app closes (crashes) or when it goes into suspended mode, to log that info, and I want the launcher to be able to know the application has stopped , unfortunately iApplicationActionManager, does not have that method. And IPackageDebugSettings which is used to change the application suspend and resume states does not have a readable current state property (afaik)
Is there any way to do this?

How to run a service as LocalSystem in Windows 7?

I am trying to write my first service application following instructions in Windows SDK. I installed the service using the following code:
SC_HANDLE schs=CreateService(sch,
SERVICENAME,"VMFS - Servidor de arquivos",
SC_MANAGER_CREATE_SERVICE,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
pathexe,
NULL/*LoadOrderGroup*/,
NULL/*TagId*/,
NULL/*Dependencies*/,
NULL/*Account:Local System*/,
NULL/*Password*/);
The server does not start(error 1053).
But, if I go to services.msc and change service to logon as my account name (Valdeci), the service starts. So this seems to be a logon error. What is wrong? I want to run my service also in Windows XP and Vista, but didn´t try it because my developing machine has Windows 7.
Try using NULL instead of ".\\LocalSystem", as described in the CreateService documentation .
I solved my problem! I followed the tips I received: stripped the the code to a "do-nothing" service and it still didn´t work. So I concluded that the problem was not the code itself. The program didn´t even start because of "missing" DLLs. I discovered that "path" works differently when running as LocalSystem, so I copied all my runtime DLLs to the folder of the service. This is the way I normally install my programs, but at development time I use the path.
Thanks for your time!

Command line application running as a windows service. Getting error 1053

I have created a c++ command line application. This application sends a revives messages from other computers and logs the results to a file. A simple application. One of the first things the app does is write to the log file the start up time.
Now that I have gotten the application to a good place, I want to install it as a service that runs on my computer (win 7).
I am using the NSIS, Simple_Service_Plugin to install the application and register the service in windows. I can see the service in windows service manager.
When I attempt to start the service, I get the following error message. The log file does not get created.
Windows could not start __THE_APP__ service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
When I start the app from explore it starts without any problems and the log file is updated correctly.
When I search this error message on-line I find lots of help for C# and .Net applications and nothing for c++ apps.
My question is:
How do I start a C++ application (not dot.net) as a service?
A service isn't a regular appliction. It's a program that uses specific system classes and implements certain features that enable the OS to communicate with it.
See here (and the surrounding pages) for more details.

CruiseControl.NET run as a windows service and as a standalone process behaves differently

I have a project that is being built using CruiseControl.NET. The project contains an 'MSBuild task' that runs the build for the project and also the unit tests. The unit test in turn is just a MSBuild 'exec' task that runs an executable.
The unit test involves some .NET remoting. And when the unit tests are run through the system command prompt, the software's window opens up, tests run and the process exits.
When I force a build through the web dashboard, the build hangs at the point where the unit test starts running. The software's window does not open up, but the executable is running. If the process is killed through the task explorer, the build goes through with a 'Failure' status. This happens when I run ccnet as a windows service.
If I run CCNet directly (not as a windows service) and force a build through the web dashboard, the build and unit tests go through fine as expected. (with the window of the software opening up.)
It looks like there is a deadlock in the case where CCNet is run as a windows service. I am guessing it is related to the standard output/error streams.
Is this is known problem?
What might be the problem going on?
Any suggestions on debugging this?
How can I get around it?
(I am using CCNet version 1.4.4 SP1)
When CCNet is running as a service it is not going to have access to the display, so don't expect to see anything on the screen in this configuration. The first thing I would check is the permissions - make sure the service runs as an account that has permissions to access whatever resources you need. You also have CCNet log files, which you can find via Dashboard.
On a side note, try TeamCity instead of CCNet, its 10 years ahead.
Maybe this answer will help :
delphi windows service can't download file from internet
You should know that when running CCNet as an application (the dosbox) it uses the environment variables and all rights from the logged account. So it may connect to a server, use cached passwords, get registry variables for this account.
BUT when ran as a service, the account is the one you provided : LocalSystem for exampe, where env. varibales are not the same.
So, what you can do is to change the CCNet service account for test. Change it to your user account (with password), and I'm sure it will work better !