-2

I want to call tshark.exe from a c++ script via ShellExecute. Is there any way to parse cmd arguments to the application? e.g. specify output file like this

tshark -w output.pcap

Here is the code

#include <Windows.h>
#include <shellapi.h>

int main()
{
    ShellExecute(NULL, "open", "tshark.exe", NULL, "C:\Program Files\Wireshark", SW_SHOWDEFAULT);
    return 0;
}
waifu_anton
  • 53
  • 2
  • 7

1 Answers1

0

The 4th parameter to ShellExecute() passes command-line arguments to the new process, eg:

ShellExecute(NULL, "open", "tshark.exe", "-w output.pcap", "C:\\Program Files\\Wireshark", SW_SHOWDEFAULT);

Though, you really should be using CreatProcess() instead (ShellExecute() is just going to call it anyway):

STARTUPINFO si = {};
PROCESS_INFORMATION pi = {};

si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWDEFAULT;

char cmd[] = "tshark.exe -w output.pcap";
if (CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, "C:\\Program Files\\Wireshark", &si, &pi))
{
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770