Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:10:55+00:00 2026-06-13T03:10:55+00:00

I’d like to execute a simple command line but without to make a window

  • 0

I’d like to execute a simple command line but without to make a window appear. Therefore I can’t use System and have to use CreateProcess as far as I know.
So I have the following code for example:

//.../

CreateProcess(NULL,input,NULL,NULL,false,NORMAL_PRIORITY_CLASS | 
 CREATE_NO_WINDOW,NULL,NULL,&startInf,&procInf);//)

//.../

If input is a line like “ping http://www.google.com -n 2” it seems to work.
What I need is the deletion-function though.
Therefore I tried a lot of variations like:

input = "rd /S /Q \"D:\\ALEX_DATEN\\PC\\C++\\bla\"";

and

  input = "rd /S /Q \"D:/DATEN/PC/C++/bla\"";

But nothing happens and the function returns failure :/
If I write it as a .bat file (without using the “\” escaping chars) the deleting works perfectly!

Does anyone know what I’m doing wrong?

P.s. no, I’m not writing a destructive virus.. if that would have been my target, I would have definitely have found simpler ways…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:10:56+00:00Added an answer on June 13, 2026 at 3:10 am

    Some system command like rd, del and … are not actual executable Images (e.g. .exe Files), so you can’t execute/run them using CreateProcess they are built-in commands that known to cmd(command interpreter of windows) so you should create cmd and pass your command to it:

    wchar_t cmd[ MAX_PATH ];
    size_t nSize = _countof(cmd);
    _wgetenv_s( &nSize, cmd, L"COMSPEC" );
    BOOL b = CreateProcessW( cmd, input, NULL, NULL, FALSE,
        NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &startInf, &procInf );
    

    Note: Please see arguments of cmd, you have to use /C to pass your command. So your command is as follow:

    wchar_t input[] = L"some command";
    wchar_t cmd[MAX_PATH] ;
    // initialize cmd
    wchar_t cmdline[ MAX_PATH + 50 ];
    swprintf_s( cmdline, L"%s /c %s", cmd, input );
    STARTUPINFOW startInf;
    memset( &startInf, 0, sizeof startInf );
    startInf.cb = sizeof(startInf);
    // If you want to redirect result of command, set startInf.hStdOutput to a file
    // or pipe handle that you can read it, otherwise we are done!
    PROCESS_INFORMATION procInf;
    memset( &procInf, 0, sizeof procInf );
    BOOL b = CreateProcessW( NULL, cmdline, NULL, NULL, FALSE,
        NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, NULL, &startInf, &procInf );
    DWORD dwErr = 0;
    if( b ) {
        // Wait till cmd do its job
        WaitForSingleObject( procInf.hProcess, INFINITE );
        // Check whether our command succeeded?
        GetExitCodeProcess( procInfo.hProcess, &dwErr );
        // Avoid memory leak by closing process handle
        CloseHandle( procInfo.hProcess );
    } else {
        dwErr = GetLastError();
    }
    if( dwErr ) {
        // deal with error here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.