Help me get rid of that pesky command window

G

Guest

I have done my due diligence over the last few days researching the net
for an answer on how to hide the pesky command window that is showing up
when I have xpe launch my custom shell.

As you can see below, I have created a small application (which is
my custom shell) used to set the current directory and launch the
java application which is my main application. As can be seen below
I tried several things to get rid of the command window (SW_HIDE,
javaw.exe, CREATE_NO_WINDOW) but to no avail.

The java application does indeed run. The standard output that the
java application generates goes to the bit bucket, everything
looks good. Except that the pesky command shell is still displayed with
nothing visible
within it.

Can anyone tell me what I am missing? How do I get rid if the seemingly
useless
black box?

Thanks in advance.
Kyle

P.S. Compiling and running this program on a normal Windows XP system using
the
GUI "Start->Run <enter your exe here>" works as described above. So
the problem is not an issue unique to XP embedded itself.

---------------------------

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>

#define BUFSIZE MAX_PATH

int _tmain(int argc, _TCHAR* argv[])
{
if (!SetCurrentDirectory(_T("c:\\MyDir"))) {
_tprintf(_T("SetCurrentDirectory failed (%d).\n"), GetLastError());
return 0;
}

STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));

// Start the child process.
if (!CreateProcess(
_T("c:\\WINDOWS\\system32\\javaw.exe"),
_T("-classpath \".;my.jar\" com.mycompany.myapp"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}

// Wait until child process exits.
//
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles.
//
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

return 0;
}
 
M

Matt Kellner [MS]

The problem here appears to be that the program was created as a Console app
rather than a Windows GUI app. Console apps don't respond to the Window
Style parameters - it's not possible to hide a Console app in the same way
as a GUI app. You could try rewriting your launcher app as a Windows GUI
app that simply never displays anything to the screen.

Also, your STARTUPINFO object is trying to apply its SW_HIDE value to the
Java application you're starting up with the launcher, not the launcher
itself. You would need to adjust the launch properties of the launcher app
outside of the app itself, or like I mentioned above, recode it so it
behaves like a Windows app (MFC GUI or similar) with no displayed dialogs.

--
Matt Kellner
SDET, Microsoft Windows XP Embedded Test Team

This posting is provided "AS IS" with no warranties, and confers no rights.
kstotz said:
I have done my due diligence over the last few days researching the net
for an answer on how to hide the pesky command window that is showing up
when I have xpe launch my custom shell.

As you can see below, I have created a small application (which is
my custom shell) used to set the current directory and launch the
java application which is my main application. As can be seen below
I tried several things to get rid of the command window (SW_HIDE,
javaw.exe, CREATE_NO_WINDOW) but to no avail.

The java application does indeed run. The standard output that the
java application generates goes to the bit bucket, everything
looks good. Except that the pesky command shell is still displayed with
nothing visible
within it.

Can anyone tell me what I am missing? How do I get rid if the seemingly
useless
black box?

Thanks in advance.
Kyle

P.S. Compiling and running this program on a normal Windows XP system
using
the
GUI "Start->Run <enter your exe here>" works as described above. So
the problem is not an issue unique to XP embedded itself.

---------------------------

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>

#define BUFSIZE MAX_PATH

int _tmain(int argc, _TCHAR* argv[])
{
if (!SetCurrentDirectory(_T("c:\\MyDir"))) {
_tprintf(_T("SetCurrentDirectory failed (%d).\n"), GetLastError());
return 0;
}

STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));

// Start the child process.
if (!CreateProcess(
_T("c:\\WINDOWS\\system32\\javaw.exe"),
_T("-classpath \".;my.jar\" com.mycompany.myapp"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}

// Wait until child process exits.
//
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles.
//
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

return 0;
}
 
G

Guest

Hi Matt,

Thank you for taking the time to respond to my query.

Your help has enabled me to solve my problem. Indeed I
had the program created as a Console App. Re-implementing
the program as a Windows GUI program solved my issue and
the command window no longer exists; the application runs
as I expect.

For others finding this thread in the future, I also removed the
SW_HIDE and associated values from the STARTUPINFO
structure (its all zeros now). I also set the 6th parameter in the
CreateProcess call to a zero value.

Thanks again for your help.

Kyle

Matt Kellner said:
The problem here appears to be that the program was created as a Console app
rather than a Windows GUI app. Console apps don't respond to the Window
Style parameters - it's not possible to hide a Console app in the same way
as a GUI app. You could try rewriting your launcher app as a Windows GUI
app that simply never displays anything to the screen.

Also, your STARTUPINFO object is trying to apply its SW_HIDE value to the
Java application you're starting up with the launcher, not the launcher
itself. You would need to adjust the launch properties of the launcher app
outside of the app itself, or like I mentioned above, recode it so it
behaves like a Windows app (MFC GUI or similar) with no displayed dialogs.

--
Matt Kellner
SDET, Microsoft Windows XP Embedded Test Team

This posting is provided "AS IS" with no warranties, and confers no rights.
kstotz said:
I have done my due diligence over the last few days researching the net
for an answer on how to hide the pesky command window that is showing up
when I have xpe launch my custom shell.

As you can see below, I have created a small application (which is
my custom shell) used to set the current directory and launch the
java application which is my main application. As can be seen below
I tried several things to get rid of the command window (SW_HIDE,
javaw.exe, CREATE_NO_WINDOW) but to no avail.

The java application does indeed run. The standard output that the
java application generates goes to the bit bucket, everything
looks good. Except that the pesky command shell is still displayed with
nothing visible
within it.

Can anyone tell me what I am missing? How do I get rid if the seemingly
useless
black box?

Thanks in advance.
Kyle

P.S. Compiling and running this program on a normal Windows XP system
using
the
GUI "Start->Run <enter your exe here>" works as described above. So
the problem is not an issue unique to XP embedded itself.

---------------------------

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>

#define BUFSIZE MAX_PATH

int _tmain(int argc, _TCHAR* argv[])
{
if (!SetCurrentDirectory(_T("c:\\MyDir"))) {
_tprintf(_T("SetCurrentDirectory failed (%d).\n"), GetLastError());
return 0;
}

STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));

// Start the child process.
if (!CreateProcess(
_T("c:\\WINDOWS\\system32\\javaw.exe"),
_T("-classpath \".;my.jar\" com.mycompany.myapp"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}

// Wait until child process exits.
//
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles.
//
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

return 0;
}
 
M

Matt Kellner [MS]

Awesome! Glad to hear this helped you. :)

--
Matt Kellner
SDET, Microsoft Windows XP Embedded Test Team

This posting is provided "AS IS" with no warranties, and confers no rights.
kstotz said:
Hi Matt,

Thank you for taking the time to respond to my query.

Your help has enabled me to solve my problem. Indeed I
had the program created as a Console App. Re-implementing
the program as a Windows GUI program solved my issue and
the command window no longer exists; the application runs
as I expect.

For others finding this thread in the future, I also removed the
SW_HIDE and associated values from the STARTUPINFO
structure (its all zeros now). I also set the 6th parameter in the
CreateProcess call to a zero value.

Thanks again for your help.

Kyle

Matt Kellner said:
The problem here appears to be that the program was created as a Console
app
rather than a Windows GUI app. Console apps don't respond to the Window
Style parameters - it's not possible to hide a Console app in the same
way
as a GUI app. You could try rewriting your launcher app as a Windows GUI
app that simply never displays anything to the screen.

Also, your STARTUPINFO object is trying to apply its SW_HIDE value to the
Java application you're starting up with the launcher, not the launcher
itself. You would need to adjust the launch properties of the launcher
app
outside of the app itself, or like I mentioned above, recode it so it
behaves like a Windows app (MFC GUI or similar) with no displayed
dialogs.

--
Matt Kellner
SDET, Microsoft Windows XP Embedded Test Team

This posting is provided "AS IS" with no warranties, and confers no
rights.
kstotz said:
I have done my due diligence over the last few days researching the net
for an answer on how to hide the pesky command window that is showing
up
when I have xpe launch my custom shell.

As you can see below, I have created a small application (which is
my custom shell) used to set the current directory and launch the
java application which is my main application. As can be seen below
I tried several things to get rid of the command window (SW_HIDE,
javaw.exe, CREATE_NO_WINDOW) but to no avail.

The java application does indeed run. The standard output that the
java application generates goes to the bit bucket, everything
looks good. Except that the pesky command shell is still displayed with
nothing visible
within it.

Can anyone tell me what I am missing? How do I get rid if the seemingly
useless
black box?

Thanks in advance.
Kyle

P.S. Compiling and running this program on a normal Windows XP system
using
the
GUI "Start->Run <enter your exe here>" works as described above. So
the problem is not an issue unique to XP embedded itself.

---------------------------

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>

#define BUFSIZE MAX_PATH

int _tmain(int argc, _TCHAR* argv[])
{
if (!SetCurrentDirectory(_T("c:\\MyDir"))) {
_tprintf(_T("SetCurrentDirectory failed (%d).\n"), GetLastError());
return 0;
}

STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));

// Start the child process.
if (!CreateProcess(
_T("c:\\WINDOWS\\system32\\javaw.exe"),
_T("-classpath \".;my.jar\" com.mycompany.myapp"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 1;
}

// Wait until child process exits.
//
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles.
//
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

return 0;
}
 

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

Top