0

how to execute ProcessStartInfo with multiple arguments?I use this code:

ProcessStartInfo psexec = new ProcessStartInfo(@"D:\psexec.exe");
psexec.Arguments = $@"\\{ip} -s cmd /c c:\Windows\System32\wbem\WMIC.exe";
psexec.Arguments = $@"\\{ip} -s cmd /c c:\Windows\System32\wbem\WMIC.exe";
Process.Start(psexec);

but only the last argument is executed. how do I make everything run in turn?

zaknafein
  • 21
  • 4
  • Does this answer your question? [How to pass multiple arguments in processStartInfo?](https://stackoverflow.com/questions/15061854/how-to-pass-multiple-arguments-in-processstartinfo) – Markus Meyer Aug 31 '22 at 04:12
  • @MarkusMeyer no – zaknafein Aug 31 '22 at 04:18
  • You are redefining arguments on line 3, instead, try using the ArgumentList property https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0#system-diagnostics-processstartinfo-argumentlist – Vinnywoo Aug 31 '22 at 04:26
  • @SithLee ProcessStartInfo does not contain the ArgumentList property – zaknafein Aug 31 '22 at 04:33
  • @zaknafein I see you must be using .net framework then, you can just use the '&' separator between commands to run one command after the other. – Vinnywoo Aug 31 '22 at 04:47
  • Why are you using `psexec` to run `cmd` to run `wmic`, why not just run `wmic` directly from `psexec`? – Charlieface Aug 31 '22 at 10:39

1 Answers1

0

If you are using .net core you can access the ArugmentList property. If not you can separate the commands with the '&' separator.

For instance, in the command prompt, you can run 2 commands like

start notepad.exe & echo hello
Vinnywoo
  • 94
  • 4