Solved

Problem spawning a regular win32 application from NT service

Posted on 1998-07-16
7
246 Views
Last Modified: 2013-11-20
Hello,

Using the sample code from "Creating a Simple Window NT Service in C++" by Nigel Thompson from Microsoft's technical article in the MSDN CDs, I created my own NT service that spawns another Win32 application called "ServerApp".  After the NT service starts,  the ServerApp is created using CreateProcess().

STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
CreateProcess(NULL, "C:\\ServerApp", NULL, NULL, FALSE,
                              0, NULL, NULL, &si, &pi);

However, for some reason, the ServeApp stays in a wait state and never completes the execution.  Even after the NT service is stopped, the ServeApp remains in the wait state.  I can't even kill the process.  How can I get the process to start?

Thanks,

Jennifer
0
Comment
Question by:jli
7 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1319343
Have you tried ShellExecute?

ShellExecute( this->GetSafeHwnd( ), "open", strEngine, NULL, strDirectory, SW_SHOWMINIMIZED );

Phillip

0
 

Author Comment

by:jli
ID: 1319344
In NT Service, there is no Windows handle associated with the process.
0
 
LVL 8

Expert Comment

by:trestan
ID: 1319345
There is no problem in the codes you listed here. Would you provide more information about the case? Did you debug your code to see where the program blocked? Or email me your codes: trestan@hotmail.com
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Expert Comment

by:Rajkumar_R
ID: 1319346
I think the problem must be in your other exe ServerApp
0
 

Expert Comment

by:ahomer
ID: 1319347
try using  ---

if(::CreateProcess(NULL, "C:\\ServerApp", NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi)){
   ::CloseHandle (pi.hThread);
   ::CloseHandle (pi.hProcess);
}            

0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1319348
Your problem does not come from CreateProcess, but from the special environment of services. Take a look at this URL for a more complete discussion of the problem.

http://www.microsoft.com/msj/0398/service2.htm


0
 

Author Comment

by:jli
ID: 1319349
Thank you.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now