Hiding the Console Window from Code

Z

zacks

I have a console application that performs a comparison of two tables
in a SQL Database. I want to invoke this application from a SQL2005
SSIS Package in an Execute Process Task. I do not want the console
window to be seen. I have this code to attempt to do this:

Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As
Long, ByVal nCmdShow As Integer) As Boolean

Sub Main()

Dim hWnd As Long

Console.Title = "Compare Tables"
hWnd = FindWindow("", "Compare Tables")
ShowWindow(hWnd, 0)

But the Console window is still visible. Any ideas on what I am doing
wrong?

While it is running, the title bar does indeed show "Compare Tables".

I have tried string.Empty and Nothing for the first parameter to the
FindWindow call, nothing helps.
 
K

kimiraikkonen

I have a console application that performs a comparison of two tables
in a SQL Database. I want to invoke this application from a SQL2005
SSIS Package in an Execute Process Task. I do not want the console
window to be seen. I have this code to attempt to do this:

Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As
Long, ByVal nCmdShow As Integer) As Boolean

Sub Main()

Dim hWnd As Long

Console.Title = "Compare Tables"
hWnd = FindWindow("", "Compare Tables")
ShowWindow(hWnd, 0)

But the Console window is still visible. Any ideas on what I am doing
wrong?

While it is running, the title bar does indeed show "Compare Tables".

I have tried string.Empty and Nothing for the first parameter to the
FindWindow call, nothing helps.

Hi,
If you're able to launch process externally, I would go with simplier
way using Shell:

' Assuming you have a console app and want to hide
Shell("c:\your_process.exe", AppWinStyle.Hide)

Hope this helps.

Regards,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top