在winXP中如何创建一个隐藏进程窗口(从任务栏)的进程?用CreateProcess函数?
/* CreateProcess initialization */
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
long ret;
// si.wShowWindow = SW_HIDE;
// hide process window.... // run in background..
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if (!CreateProcess(0, exe,
0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi)) {
return;
}
//int prez = WaitForSingleObject(pi.hProcess, INFINITE);
//CloseHandle(pi.hProcess);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试设置 dwFlags 成员="noreferrer">
STARTUPINFO
结构为STARTF_USESHOWWINDOW
,wShowWindow
成员为SW_HIDE
。这将使
CreateProcess()
将 0 作为WinMain
。但是,并非所有 Windows 应用程序都表现良好并使用此值来初始调用ShowWindow()
。You can attempt to set the
dwFlags
member of yourSTARTUPINFO
structure toSTARTF_USESHOWWINDOW
and thewShowWindow
member toSW_HIDE
.This will make
CreateProcess()
pass 0 as thenCmdShow
parameter ofWinMain
. However, not all Windows application are well behaved and use this value to the initial call toShowWindow()
.不是您(新进程的创建者)将新进程注册到任务栏中。这是创建一个顶级窗口的新进程,该窗口决定是否位于任务栏中。该决定基于该顶级窗口的扩展样式,该样式由新进程决定。
换句话说,您必须在另一个进程中查看顶级窗口才能执行此操作。
It's not you, the creator of the new process, that registers the new process into the task bar. It's the new process that creates a top-level window that decides whether or not to be in the taskbar. This decision is based on the extended style of that top-level window, which is determined by the new process.
In other words, you'd have to poke at the top-level window in this other process in order to do this.
您可以找到与启动的进程关联的窗口(请参阅
FindWindow
和EnumWindows
),并调用ShowWindow
函数与SW_HIDE
。或者,您可以通过删除WS_EX_APPWINDOW
并添加WS_EX_TOOLWINDOW
来修改窗口的扩展样式。如果启动的进程遵循设置,最简单的方法仍然是使用第一个答案中所述的 STARTUPINFO 。
You can find the window associated with the started process (see
FindWindow
andEnumWindows
), and callShowWindow
function withSW_HIDE
. Alternatively you can modify the extended style of the window by removingWS_EX_APPWINDOW
and addingWS_EX_TOOLWINDOW
.The simplest way is still to use STARTUPINFO as described in the first answer, if the started process respects the setting.