Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating hidden processes (window not visible)

I'm using CreateProcess() with startup flags set to STARTF_USESHOWWINDOW and SW_HIDE to start an application in the background with its window hidden. I'm doing this to run a scheduled maintenance tasks and i don't want to be bothered with windows.

In most cases the windows are hidden but there are cases where the program's window pops right out in front of you (for example Google's Chrome - i started testing with different apps to see whether this was a once time problem but nope...).

This happens less in Windows XP, but it happens a lot on Vista.

Is there a flag that I am missing? Is there any other way to create a process with its window hidden?

Thanks!

my sample code is:

char *ProgramName  
STARTUPINFO StartupInfoF;
PROCESS_INFORMATION ProcessInfoF;

memset(&StartupInfoF, 0, sizeof(StartupInfoF));
memset(&ProcessInfoF, 0, sizeof(ProcessInfoF));

StartupInfoF.cb = sizeof(StartupInfoF);
StartupInfoF.wShowWindow = SW_HIDE;
StartupInfoF.dwFlags = STARTF_USESHOWWINDOW;    

if (CreateProcess(ProgramName,
                  "",                 
                  0,
                  0,
                  FALSE,
                  DETACHED_PROCESS,
                  0,
                  0,                              
                  &StartupInfoF,
                  &ProcessInfoF) == FALSE)
{
  // error
}
else
{
  // OK
}
like image 804
wonderer Avatar asked Apr 28 '26 05:04

wonderer


1 Answers

You can start the process on another desktop, using the lpDesktop member of the STARTUPINFO structure passed to CreateProcess. This way the process will have all its windows shown, but on another desktop, so you (or your users) won't be bothered with it.

I've never worked with multiple desktops so I can't say what would be the side effects, but I think it's doable. Start by looking into CreateDesktop and move onward.

like image 95
eran Avatar answered Apr 29 '26 20:04

eran