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
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 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!!!
Technology Partners: 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

615 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