CreateProcess with CREATE_NO_WINDOW

Posted on 2001-09-10
Last Modified: 2012-05-04
Hi all,

Does anybody know how to use the CREATEPROCESS API with a CREATE_NO_WINDOW so that a window, of course, is not created when the process is created/executed?

Basically, a CREATEPROCESS call that works the same way as a SHELL statement with a vbHide qualifier is used?

Any assistance would greatly be appreciated.

Question by:davism
  • 3
  • 2
  • 2
  • +1

Expert Comment

ID: 6472357
I will place a comment only first on this one.  You can not EVER make a process in windows that needs a window not have one.  This would break the windows message system.  BUT what you can do and what I would suggest is just make it hidden...

Sorry if I missed what you are asking but seems to be what you may need by the text above.

Author Comment

ID: 6472386
How can I make that hidden with a CREATEPROCESS?  Again, I know I can do that with the SHELL with the vbHide qualifer but how can I do that (i.e. hidden) with a CREATEPROCESS?  

Accepted Solution

trkcorp earned 100 total points
ID: 6472395
This will start a "windowed" process and hide it from you.  WARNING: You will have to go into task manager and manually terminate NOTEPAD.EXE in order to end this program normally since notepad will not end itself and you will be unable to see it...

'Create a module and add this code:

Option Explicit
'Global Constants
Global Const SW_HIDE = &H0&
Global Const INFINITE = -1&

'CreateProcess parm structures
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadID As Long
End Type

Declare Function CreateProcessA Lib "kernel32" _
   (ByVal lpApplicationName As Long, ByVal lpCommandLine As _
   String, ByVal lpProcessAttributes As Long, ByVal _
   lpThreadAttributes As Long, ByVal bInheritHandles As _
   Long, ByVal dwCreationFlags As Long, ByVal _
   lpEnvironment As Long, ByVal _
   lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, _
   lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
  ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (hObject As Long) _
    As Boolean

'Using a form with a button to execute the following:

Private Sub Command1_Click()
Dim AppToRun As String
Dim rc As Long

NameStart.cb = Len(NameStart)
NameStart.wShowWindow = SW_HIDE

' Launch notepad and wait for its completion
AppToRun = "notepad.exe"
rc = CreateProcessA(0&, AppToRun, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, NameStart, NameofProc)
rc = WaitForSingleObject(NameofProc.hProcess, INFINITE)
rc = CloseHandle(NameofProc.hProcess)
End Sub

Hope this helps!!!
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Expert Comment

ID: 6472916

Not veru sure if this is what you need, but here it is:

Description: Make a "formless" program with a system tray icon (3K)

You could simply kick out the code for putting the icon in the sys tray.  FYI, I've come across code which doesn't use the Form gived in VB, but simply a *.bas file.  Is that what you're looking for anyway? - Can't promise I'll be able to find it though, but I'll try if that's what you need.

That's it!

glass cookie : )

Expert Comment

ID: 6472917

Not veru sure if this is what you need, but here it is:

Description: Make a "formless" program with a system tray icon (3K)

That's it!

glass cookie : )

Expert Comment

ID: 6473032
As glass cookie alluded to, and you may already know, you may have an executable created from just a .bas module and no forms at all.  You set the start up object on the project properties window general tab to Sub Main and create a .bas module with a Sub Main() routine...

Also, in my example above, by commenting out the code:
rc = WaitForSingleObject(NameofProc.hProcess, INFINITE)
rc = CloseHandle(NameofProc.hProcess)
you can launch a process and not wait or monitor it but I wouldn't advise doing it unless it will "self-terminate".  You can even exit the launcing program and leave the launched process active.

If you change the constant SW_HIDE thusly:
Global Const SW_HIDE = &H1&
You will be saying in effect, do not hide the process. You can then see it and wait on it as if it were a modal form, or not wait by commenting out as in the prior paragraph.  Doing the latter you can, as I said, exit the launching program leaving the launched one running...

The above example was originally written to run BCP.exe (a DOS SQL Bulk copy command) in background. (no dos window) It will, however, run any process but as you will see if you have a windowed process the API as stated will not allow you to see the window, but it will launch the process and run any code that runs without intervention.  If your real purpose is to launch a windowed program but not have it take focus, then just use SHELL and do a ME.ZORDER to place your launching program back in foreground.

Author Comment

ID: 6474316
Worked out great.  Thanks much.  In response to your later comment as well - I did work with certain aspect as in removing the waitforsingleobject, etc because I didn't have to wait for it.

One thing I did notice however, is this is using the CREATEPROCESSA where as I had a previous API of CREATEPROCESS which had a alias of CREATEPROCESSA but the fundamental parameter datatypes where different.  For instance, the very first parameter of the lpApplication name in the CREATEPROCESS API was a datatype of string and in the CREATEPROCESSA API it is a long.

Any idea on the reasons for the differences?  

But very much appreciated on the answer.  It worked out great.  :-)

Expert Comment

ID: 6474614
Nope, I don't have my trusty API book in my hand... But Glad that I could help.  You are welcome.

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 433
Exit a vb6 apps when a calling it apps closes 15 49
Advice in Xamarin 21 80
IF ELSE Statement in Excel Macro VBA 16 65
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question