创建独立进程!
我正在尝试从 C++ 中的服务创建一个进程。这个新进程是作为子进程创建的。我想创建一个独立的进程而不是子进程...
我正在使用 CreateProcess 函数来实现相同的目的。由于我创建的新进程是一个子进程,当我尝试在服务级别杀死进程树时,它也会杀死子进程......我不希望发生这种情况。我希望创建的新进程独立于服务运行。
请同样的建议.. 谢谢..
代码
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si); // Start the child process.
ZeroMemory( &pi, sizeof(pi) );
si.dwFlags = STARTF_USESHOWWINDOW;
if(bRunOnWinLogonDesktop)
{
if(csDesktopName.empty())
si.lpDesktop = _T("winsta0\\default");
else
_tcscpy(si.lpDesktop, csDesktopName.c_str());
}
if(bHide)
si.wShowWindow = SW_HIDE; /* maybe even SW_HIDE */
else
si.wShowWindow = SW_SHOW; /* maybe even SW_HIDE */
TCHAR szCmdLine[512];
_tcscpy(szCmdLine, csCmdLine.c_str());
if( !CreateProcess( NULL,
szCmdLine,
NULL,
NULL,
FALSE,
CREATE_NEW_PROCESS_GROUP,
NULL,
NULL,
&si,
&pi ) )
I am trying to create a process from a service in C++. This new process is creating as a child process. I want to create an independent process and not a child process...
I am using CreateProcess function for the same. Since the new process i create is a child process when i try to kill process tree at the service level it is killing the child process too... I dont want this to happen. I want the new process created to run independent of the service.
Please advice on the same..
Thanks..
Code
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si); // Start the child process.
ZeroMemory( &pi, sizeof(pi) );
si.dwFlags = STARTF_USESHOWWINDOW;
if(bRunOnWinLogonDesktop)
{
if(csDesktopName.empty())
si.lpDesktop = _T("winsta0\\default");
else
_tcscpy(si.lpDesktop, csDesktopName.c_str());
}
if(bHide)
si.wShowWindow = SW_HIDE; /* maybe even SW_HIDE */
else
si.wShowWindow = SW_SHOW; /* maybe even SW_HIDE */
TCHAR szCmdLine[512];
_tcscpy(szCmdLine, csCmdLine.c_str());
if( !CreateProcess( NULL,
szCmdLine,
NULL,
NULL,
FALSE,
CREATE_NEW_PROCESS_GROUP,
NULL,
NULL,
&si,
&pi ) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关闭子进程的线程和进程处理程序后,它仍然是 Process Explorer 中的子进程,但结束父进程不会导致子进程终止。
我在 ReactOS 的 cmd.exe 来源,在执行过程中 '启动'命令。
After closing thread and process handlers of the child process, it's still a child in the Process Explorer, but ending parent process doesn't cause termination of the child one.
I've found this decision in sources of cmd.exe of the ReactOS, in the procedure of executing 'start' command.
创建一个中间进程(使用create_new_process_group),然后创建真正的进程。
中间进程应该在启动真正进程后立即退出。
Create an intermediate process (use create_new_process_group), which then creates the real process.
The Intermediate process should exit as soon as it's launched the real process.