🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5641

Re: Execute system command w/o DOS window?

#5641
From: Ed Mulroy
Date: Tue, 26 Jul 2005 17:10
37 lines
1940 bytes
---------------------
#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  {
  char cmd_line[2048];

  // get name and path of the command interpreter
  GetEnvironmentVariable("COMSPEC", cmd_line, sizeof(cmd_line));
  strcat(cmd_line, " /C dir >dirlist.txt"); // add the DOS command
  WinExec(cmd_line, SW_HIDE);
  MessageBox(
    HWND_DESKTOP,
    "Now look at the contents of DirList.txt",
    "",
    MB_OK);
  return 0;
  }
---------------------

Microsoft's help on Windows suggests that WinExec will go away back in the 
mid 90's.  Since some of Windows' own code uses it, it is unlikely that 
WinExec will go away.

CreateProcess would also work.

.  Ed

> TerryC wrote in message
> news:42e6608a$1@newsgroups.borland.com...
>
> I seem to remember a Win32 API function for executing a command
> without opening a Command Prompt window to do it.  Could somebody
> help me out?
>
> system("<command>") works, but opens the Command Prompt window.
Technical Details
Message-ID: <42e66e7a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42e6608a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f51638e82cb7b57
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ed Mulroy" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42e6608a$1@newsgroups.borland.com>
Subject: Re: Execute system command w/o DOS window?
Date: Tue, 26 Jul 2005 13:10:17 -0400
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 4.238.208.72
Message-ID: <42e66e7a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1122397818 4.238.208.72 (26 Jul 2005 10:10:18 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail