Solved

CreateProcess with CREATE_NO_WINDOW

Posted on 2001-09-10
8
2,235 Views
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.

Thanks
0
Comment
Question by:davism
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Expert Comment

by:cf101
Comment Utility
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.
0
 
LVL 1

Author Comment

by:davism
Comment Utility
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?  
0
 
LVL 4

Accepted Solution

by:
trkcorp earned 100 total points
Comment Utility
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 NORMAL_PRIORITY_CLASS = &H20&
Global Const STARTF_USESHOWWINDOW = &H1&
Global Const SW_HIDE = &H0&
Global Const INFINITE = -1&

'CreateProcess parm structures
Type STARTUPINFO
    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

Type PROCESS_INFORMATION
  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 NameStart As STARTUPINFO
Dim rc As Long
Dim NameofProc As PROCESS_INFORMATION

NameStart.cb = Len(NameStart)
NameStart.dwFlags = STARTF_USESHOWWINDOW
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)
Me.Refresh
rc = WaitForSingleObject(NameofProc.hProcess, INFINITE)
rc = CloseHandle(NameofProc.hProcess)
End Sub

Hope this helps!!!
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Hi!

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

Download...
http://www.vb-helper.com/HowTo/tray3.zip
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 : )
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Hi!

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

Download...
http://www.vb-helper.com/HowTo/tray3.zip
Description: Make a "formless" program with a system tray icon (3K)

That's it!

glass cookie : )
0
 
LVL 4

Expert Comment

by:trkcorp
Comment Utility
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.
0
 
LVL 1

Author Comment

by:davism
Comment Utility
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.  :-)
0
 
LVL 4

Expert Comment

by:trkcorp
Comment Utility
Nope, I don't have my trusty API book in my hand... But Glad that I could help.  You are welcome.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now