Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting a GUI app in hidden mode?

Status
Not open for further replies.

haddaway

Programmer
Jul 6, 2005
172
0
0
SE
I am using the following code:

Dim si As New ProcessStartInfo
si.CreateNoWindow = True
si.UseShellExecute = False
si.WindowStyle = ProcessWindowStyle.Hidden
si.FileName = "notepad.exe"

Process.Start(si)

This is just an example, but I would like to start my application in hidden mode AND redirect output. But this does not work! Any ideas why the above code does not work?
 
Setting:
Code:
si.UseShellExecute = True
hides the application.

If that's what you are trying to achieve.

Regards,
mansii
 
Yes, but that prevents me from redirecting output.
 
Play arround with this:

1. Create an old styled Batch file in C:\ folder -> Test.Bat
Code:
dir c:\ > %1

2. Pass the argument
Code:
Dim si As New ProcessStartInfo
si.WindowStyle = ProcessWindowStyle.Normal
si.CreateNoWindow = True
si.UseShellExecute = False
si.FileName = "C:\Test.Bat"
si.RedirectStandardOutput = True
si.Arguments = "c:\TestResult.txt"
Dim p As New Process
p.StartInfo = si
p.Start()
p.StandardOutput.ReadToEnd()
p.WaitForExit()

make sure that your application close itself when it finishes processing, so it (the process) doesn't stay in memory.

Regards,
mansii
 
That works for a commandwindow. I would like to have the ability to do this with for example Notepad.exe. Unfortunately, that program and other "real" GUI programs won't hide like they do when using the WindowsAPI function "CreateProcessWithLogonW".
 
Apologize, haddaway. But I did not get what you are trying to achieve. I.e. Start the Notepad.exe (for example) then hide it from any user.

Perhaps, a Windows Service application is more suitable.

 
Thanks mansii, Notepad was just an example. It could be any GUI application. I don't know why they have failed with this or if there exists a workaround.

If someone wants to try this further here is what I want to achieve in my example:

1. start Notepad.exe in hidden mode via Process.Start, no bat file, just pointing to the exe
2. enable redirect output (even though Notepad does not give any output - again, this is just an example)

 
As far as I am aware only console apps use the redirectable stdin and stdout handles, WinForms apps don't. So I don't think that you will be able to achieve both objectives with regard to starting any one particular application.

In other words, if the app you want to start is a console app you can redirect stdin and stdout (and hide the window) - for a WinForms app you can only hide the window, although you may be able to locate the handles of the form's UI elements and pick up the contents of those.


Hope this helps.

[vampire][bat]
 
Yes, maybe they don't. But I would like to have the possibility to hide it. My problem is that I always capture output, but it is the user that selects an application to start and sometimes they want to hide the GUI applications. I don't know any way to determine if it is a GUI application or not programatically. If I could, I would stop the automatic output. When using the Windows API function CreateProcessWithLogonW I am able to redirect and hide, I wish that was possible in process.start as well.

Anyway, do you know a way to determine if it's a gui app or not, programatically?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top