• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

MS Windows - C++ how to spawn process from my Windows service code in async mode

how to spawn process from my Windows service  C++ code in async mode.
Non blocking. Not using .NET just C++ code.


0
longjumps
Asked:
longjumps
  • 3
  • 2
4 Solutions
 
AndyAinscowCommented:
Have a look at CreateProcess in the help files.
There are links to example code (and alternatives - I am not certain it is suitable if you are running a service).
0
 
jkrCommented:
Is there anything special about the whole thing? If not, just use what Andy recommended.
0
 
longjumpsAuthor Commented:
I need to run process from my Windows Service in non blocking mode.

How to do this?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jkrCommented:
Andy already told you that - or, in a nutshell:
DWORD ExecuteProcess   (   LPSTR   pszCmd, BOOL bShow)
{
    STARTUPINFO         si;
    PROCESS_INFORMATION pi;

    BOOL                bRes;

    DWORD               dwCode  =   0;

    MSG                msg;

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb           =   sizeof  (   STARTUPINFO);
    si.dwFlags      =   STARTF_USESHOWWINDOW;
    si.wShowWindow  =   bShow ? SW_SHOWNORMAL : SW_HIDE;

    bRes    =   CreateProcess   (  NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

    return bRes ? (DWORD) pi.hProcess : -1; 
}

Open in new window

0
 
AndyAinscowCommented:
CreateProcess is non-blocking (as you specified).  Read about it and what it can do - there are a LOT of options.
There is also example code in the help files.

My only concern is that you are running a service.  If it is not suitable for that then there are alternatives listed in the documentation.
0
 
jkrCommented:
I was more concerned about spawning a process that then is visible to the user, but since this does not seem to be the case...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now