Home > Windows API > How to start a process hidden!

How to start a process hidden!

I’ve seen people asking this question number of times, so for those people here is the answer…

When creating a process via CreateProcess we’ve got to give a STARTUPINFO structure as a parameter which specifies startup options for a process.

Set dwFlags member to STARTF_USESHOWWINDOW to indicate that we will be using wShowWindow member of STARTUPINFO. Then set wShowWindow to SW_HIDE to start a process as hidden.

To start a process as maximized use SW_MAXIMIZE, to start as minimized use SW_MINIMIZE, to start as restored use SW_RESTORE. Look up ShowWindow MSDN to for other options!

STARTUPINFO StartInfo = { 0 };
StartInfo.cb = sizeof( StartInfo ); 

// Use showwindow field of this structure
StartInfo.dwFlags = STARTF_USESHOWWINDOW;
StartInfo.wShowWindow = SW_HIDE; 

PROCESS_INFORMATION pi = { 0 };
CreateProcess( _T( "C:\\windows\\Notepad.exe" ),
               NULL,
               NULL,
               NULL,
               FALSE,
               0,
               NULL,
               NULL,
               &StartInfo,
               &pi );

You won’t see notepad running since it’s hidden, open task manager to see notepad running!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: