Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


CreateProcess with CREATE_NO_WINDOW

Posted on 2001-09-10
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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!!!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

670 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