Article View: borland.public.cppbuilder.nativeapi
Article #12708Re: ShellExecute Error
From: Ed Mulroy [TeamB]
Date: Fri, 21 Nov 2003 16:23
Date: Fri, 21 Nov 2003 16:23
47 lines
2609 bytes
2609 bytes
The function system won't hide the console window.
Use CreateProcess or WInExec. Use GetEnvironmentVariable to get the string
containing the name associated with "COMSPEC" and use that string as the
name of the program to execute. Use the command line you currently have
with "/C " added at the begininng.
CreateProcess is a bit involved to type in all the args for in a message so
I'll use WinExec instead. This illustrates the technique:
--------------------------
#include <windows.h>
void RunACommand(const char *cmd_2_run)
{
// big buffer because we don't know how big cmd_2_run will be
char buf[2 * MAX_PATH + 1];
// get name and path of command processor into 'buf'
GetEnvironmentVariable("COMSPEC", buf, sizeof(buf));
// append /c followed by the command to 'buf'
// lstrlen and wsprintf are Windows functions equivalent
// to strlen and sprintf
wsprintf(buf + lstrlen(buf), " /c %s", cmd_2_run);
// SW_HIDE says to hide the console window
WinExec(buf, SW_HIDE);
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// your machine might use c:\windows instead of c:\winnt
RunACommand("dir /s c:\\winnt\\*.log >loglist.txt");
return 0;
}
--------------------------
. Ed
> George wrote in message
> news:3fbdc0ec@newsgroups.borland.com...
>
> system() seems to be a very good solution. Do you know
> a way to make the window that popups to be hidden
> (invisible) ? With createprocess you can give the process
> the SW_HIDE. What about the system() ?
Technical Details
Message-ID:
<3fbe3c1d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fbd4eec$1@newsgroups.borland.com> <k42orvgo0cuq8t40gna3l1u57oklbuk107@4ax.com> <3fbdc0ec@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9b656969a1fc70df X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-21 08:41:03 PST From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fbd4eec$1@newsgroups.borland.com> <k42orvgo0cuq8t40gna3l1u57oklbuk107@4ax.com> <3fbdc0ec@newsgroups.borland.com> Subject: Re: ShellExecute Error Date: Fri, 21 Nov 2003 11:23:46 -0500 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <3fbe3c1d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1069431837 24.74.175.102 (21 Nov 2003 08:23:57 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail