Win API To Run Arbitrary Command?

john weiss 21 Reputation points
2021-06-09T15:53:12.267+00:00

What's API to execute an arbitrary command-line command?

ShellExecuteEx seems only appropriate if you're using a verb, like open or edit.

thx

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,431 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 112.8K Reputation points
    2021-06-09T16:45:48.197+00:00

    Usually you can use system or _wsystem, for example: system("dir C:\").

    0 comments No comments

  2. Castorix31 81,836 Reputation points
    2021-06-09T17:48:30.647+00:00

    You can use ShellExecute with NULL for default or "open" verb :

    HINSTANCE h = ShellExecute(NULL, NULL, L"cmd.exe", L"/c dir c: > c:\\temp\\test.txt", NULL, SW_HIDE);
    
    0 comments No comments